我有一个程序,我基本上需要从 StringBuilder 加载富文本。
问题是,有时我会得到一个 100,000 行长的字符串(这是程序的可能情况),包括 Rtf 代码和颜色。
问题不在于构建字符串,而在于当我将 Rtf 属性分配给 StringBuilder.ToString() 时,需要花费 4 分钟的时间来加载。
TextBox.Rtf = Build.ToString();
如果我从 StringBuilder 复制相同的字符串,并将其加载到写字板中,则大约需要 2 或 3 秒。我使用 SendMessage() 和 WM_SETREDRAW 禁用 RTB 的重绘,但这不会改变任何内容。
有什么建议吗?
I have a program where I basically need to load Rich Text from a StringBuilder.
The problem is, somethimes I get a string that is 100,000 lines long (and this is a possible situation for the program), including Rtf codes and colours.
The problem isn't building the string, it's when I asign the Rtf property to the StringBuilder.ToString(), it takes a solid 4 minutes to load.
TextBox.Rtf = Build.ToString();
If I copy this same string from the StringBuilder, and load it in WordPad, it takes about 2 or 3 seconds. I am diabling the RTB's redrawing by using SendMessage() and WM_SETREDRAW, but that doesn't change anything.
Any suggestions?
发布评论
评论(3)
RichTextBox
使用riched20.dll
,它是 Rich Edit Control 库的v3.0
“http://www.microsoft.com”rel="nofollow noreferrer">微软。但是,写字板使用msfedit.dll
版本为4.1
。版本
4.1
比v3.0
快约 30 倍请参阅此内容以了解有关版本的更多信息
MSDN 关于 Rich Edit 控件
RichTextBox
usesriched20.dll
which is thev3.0
of the libraryRich Edit Control
of Microsoft. However, WordPad usesmsfedit.dll
which is version4.1
.Version
4.1
is about 30 times more faster thanv3.0
See this for more information about versions
MSDN About Rich Edit Controls
抱歉,RTB 控件不会削减 10,000 行,更不用说 100,000 行了。
优化它的一种可能的方法是从文件或流加载,但我不怀疑会有多大改进。
Sorry, but the RTB control is not gonna cut 10,000 lines, nevermind 100,000.
One possible way to optimize it, is to load from a file or stream instead, but I dont suspect much improvement.
只是猜测,但是否会触发 GC(垃圾收集器)?不过这不应该持续4分钟......
Just a guess, but could it be that the GC (garbage collector) gets triggered? That shouldn't last 4 minutes though...