<bdo id='afSw6'></bdo><ul id='afSw6'></ul>
  1. <legend id='afSw6'><style id='afSw6'><dir id='afSw6'><q id='afSw6'></q></dir></style></legend>
  2. <i id='afSw6'><tr id='afSw6'><dt id='afSw6'><q id='afSw6'><span id='afSw6'><b id='afSw6'><form id='afSw6'><ins id='afSw6'></ins><ul id='afSw6'></ul><sub id='afSw6'></sub></form><legend id='afSw6'></legend><bdo id='afSw6'><pre id='afSw6'><center id='afSw6'></center></pre></bdo></b><th id='afSw6'></th></span></q></dt></tr></i><div id='afSw6'><tfoot id='afSw6'></tfoot><dl id='afSw6'><fieldset id='afSw6'></fieldset></dl></div>

      <tfoot id='afSw6'></tfoot>

    1. <small id='afSw6'></small><noframes id='afSw6'>

    2. 将大量文本写入文本框

      时间:2023-06-09
    3. <small id='pxFco'></small><noframes id='pxFco'>

            <i id='pxFco'><tr id='pxFco'><dt id='pxFco'><q id='pxFco'><span id='pxFco'><b id='pxFco'><form id='pxFco'><ins id='pxFco'></ins><ul id='pxFco'></ul><sub id='pxFco'></sub></form><legend id='pxFco'></legend><bdo id='pxFco'><pre id='pxFco'><center id='pxFco'></center></pre></bdo></b><th id='pxFco'></th></span></q></dt></tr></i><div id='pxFco'><tfoot id='pxFco'></tfoot><dl id='pxFco'><fieldset id='pxFco'></fieldset></dl></div>
                <tbody id='pxFco'></tbody>
              <tfoot id='pxFco'></tfoot>
                <bdo id='pxFco'></bdo><ul id='pxFco'></ul>
              • <legend id='pxFco'><style id='pxFco'><dir id='pxFco'><q id='pxFco'></q></dir></style></legend>

                本文介绍了将大量文本写入文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在将大量格式化文本的日志写入 .net windows 窗体应用程序中的文本框.

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

                一旦数据超过几兆,它就会变慢.由于我要附加字符串,因此每次都必须重新分配对吗?我只需要将值设置为文本框一次,但在我的代码中我正在执行 line+=data 数万次.

                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.

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

                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 重启进程

                这篇关于将大量文本写入文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 TextBox 中保存用户输入的值?(WPF、XAML) 下一篇:WPF:当 TextBox 具有焦点时为 ListBox 设置 IsSelected,而不会丢失 LostFocus 上

                相关文章

                <small id='d9gnz'></small><noframes id='d9gnz'>

                <legend id='d9gnz'><style id='d9gnz'><dir id='d9gnz'><q id='d9gnz'></q></dir></style></legend>
                <i id='d9gnz'><tr id='d9gnz'><dt id='d9gnz'><q id='d9gnz'><span id='d9gnz'><b id='d9gnz'><form id='d9gnz'><ins id='d9gnz'></ins><ul id='d9gnz'></ul><sub id='d9gnz'></sub></form><legend id='d9gnz'></legend><bdo id='d9gnz'><pre id='d9gnz'><center id='d9gnz'></center></pre></bdo></b><th id='d9gnz'></th></span></q></dt></tr></i><div id='d9gnz'><tfoot id='d9gnz'></tfoot><dl id='d9gnz'><fieldset id='d9gnz'></fieldset></dl></div>

              • <tfoot id='d9gnz'></tfoot>
                    • <bdo id='d9gnz'></bdo><ul id='d9gnz'></ul>