C#RichTextBox的内存不足 [英] c# richtextbox outofmemory

查看:1047
本文介绍了C#RichTextBox的内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个应用程序,读取输入的聊天(有点像即时通讯),格式化它并将其插入到一个RichTextBox。如果离开了程序足够长的时间运行,你会得到一个内存不足的错误。看着我的代码后,我想这是因为我从来没有修剪的RichTextBox。我快到的问题是我不希望调用clear(),因为我不希望看到的文本消失。我想也许我应该保持一个列表像200线的财产以后的最大尺寸。此列表将保持最近的聊天。如果聊天日志增长到大,通话清晰并重新插入最后200行。然而,我实现了在此之前想过,如果有人更好的解决方案都知道我会问。 ?有什么想法

I have written an app that reads incoming chat(somewhat like an instant messenger), formats it and inserts it into a richtextbox. If you leave the program running long enough you will get an out of memory error. After looking at my code i think this is because i am never trimming the richtextbox. The problem that i'm running into is i don't want to call clear() because i don't want the visible text to disappear. I was thinking maybe i should keep a List with a max size of somthing like 200 lines. This List would keep the most recent chat. If the chat log grows to big, call clear and reinsert the last 200 lines. However, before i implement this thought i would ask if anyone knows of a better solution. Any thoughts?

推荐答案

我可能会做到以下几点:

I would probably do the following:


  1. RichTextBox.TextChanged 事件

  2. 在处理程序,检查线路(<$ C的数量$ C> RichTextBox.Lines.Length )

  3. 如果这超过最大,删除第一个。

  1. Catch the RichTextBox.TextChanged event
  2. In the handler, check the number of lines (RichTextBox.Lines.Length)
  3. If this exceeds your maximum, remove the first.

祝你好运!

这篇关于C#RichTextBox的内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆