阅读大量的字符和更新文本框 [英] Reading lots of characters and updating a textbox

查看:141
本文介绍了阅读大量的字符和更新文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从一个流(由一过程提供)逐字符读取数据并且将它添加到文本框,使用户可以看到。唯一的问题是,这是 SLOW 。用户需要查看的数据,因为它被提供给程序(几乎没有延迟)。我想是这样的终端如何处理文本,它可以通过如此之快,这是一个模糊的滚动。

I am reading data from a stream (provided by a process) character by character and adding it to a textbox so the user can see. The only problem is, this is SLOW. The user needs to see the data as it is given to the program (with little to no delay). I would like something like how terminals handle text, it can scroll by so fast that it's a blur.

如何改进呢?

有关的参考,我使用C#.NET3.5和WinForms。

For reference, I'm using C# .net3.5 and winforms.

推荐答案

文本框的文本属性是一个字符串,字符串是不可变(这意味着你可以'T改变字符串)。这意味着每个你添加一个角色的时候,你会创建一个字符串的新副本,一个字符在末尾添加。

The Text property of the text box is a string, and strings are immutable (meaning that you can't change a string). This means that each time that you add a character, you will be creating a new copy of the string with one character added at the end.

如果您例如在文本框10000字,你将复制数据的20KB添加下一个字符。添加一百个字符一次一个装置数据的复制2MB

If you for example have 10000 characters in the textbox, you will be copying 20kB of data to add the next character. Adding a hundred characters one at a time means copying 2MB of data.

如果该数据是基于行,而不是使用文本框列表,让你只有当您添加字符以更新的最后一行。

If the data is line based, use a list instead of a text box, so that you only have to update the last line when you add a character.

这篇关于阅读大量的字符和更新文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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