写文字的巨额资金的文本框 [英] Writing huge amounts of text to a textbox

查看:106
本文介绍了写文字的巨额资金的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.NET窗口写入日志很多很多格式文本到文本框的形式应用。

I am writing a log of lots and lots of formatted text to a textbox in a .net windows form app.

这是缓慢的,一旦数据得到过几兆。由于我将字符串已被重新分配每一次吧?我只需要将该值设置为文本框一次,但在我的代码我做行+ =数据数十倍十万。

It is slow once the data gets over a few megs. Since I am appending the string has to be reallocated every time right? I only need to set the value to the text box once, but in my code I am doing line+=data tens of thousands of times.

有一个更快的方法来做到这一点?也许不同的控制?有没有我可以使用链表string类型?

Is there a faster way to do this? Maybe a different control? Is there a linked list string type I can use?

推荐答案

的StringBuilder不会帮助,如果文本框添加到增量,如日志输出示例。

StringBuilder will not help if the text box is added to incrementally, like log output for example.

但是,如果上面是真实的,如果你的更新不够频繁,可能理应你为缓存一定数量的更新,然后它们附加在一个步骤中(而不是不断地追加)。 。这将节省你很多字符串重新分配......然后StringBuilder的将是有益的。

But, if the above is true and if your updates are frequent enough it may behoove you to cache some number of updates and then append them in one step (rather than appending constantly). That would save you many string reallocations... and then StringBuilder would be helpful.

注:


  1. 创建一个类范围的StringBuilder成员(_sb)

  2. 启动一个定时器(或使用计数器)

  3. 附加文字更新到_sb

  4. 当计时器滴答声或某些计数器达到复位,并追加到
    文本框

  5. 重新启动进程#1

  1. Create a class-scoped StringBuilder member (_sb)
  2. Start a timer (or use a counter)
  3. Append text updates to _sb
  4. When timer ticks or certain counter reached reset and append to text box
  5. restart process from #1

这篇关于写文字的巨额资金的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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