简体   繁体   English

RichTextBox性能问题(文本框中的文本过多)

[英]RichTextBox performance issues(Too much text in the textbox)

Currently I am trying to load my log files into a RichTextBox, but the problem is that when I scroll down the text always loads because the log file has a lot of data (65mb). 当前,我正在尝试将日志文件加载到RichTextBox中,但是问题在于,当向下滚动文本时,总是会加载文本,因为日志文件中包含大量数据(65mb)。 The performance deteriorates so much within 50 seconds that my program freezes. 性能在50秒之内恶化得如此之多,以至于我的程序无法运行。

Does anyone have improvement suggestions or a solution for me . 是否有人对我有改进建议或解决方案。 My current trainee task is to write a search tool where you can read log files and search them for certain keywords. 我当前的受训者任务是编写一个搜索工具,您可以在其中读取日志文件并在其中搜索某些关键字。 Should I possibly use an element other than a RichTextBox? 是否应该使用RichTextBox以外的其他元素?

65meg of data is a lot to hold into memory, whichever way you look at this. 无论您以哪种方式查看,都需要将65meg的数据保存到内存中。

Meaning there could well be other issues you will encounter along the way. 这意味着您在此过程中可能还会遇到其他问题。

Work on them when you find them though. 当找到它们时,对它们进行处理。

For now you need something that can possibly work. 目前,您需要一些可能有效的工具。

This sample here uses a listbox to present a row per line. 此示例在此处使用列表框显示每行一行。

Each row is a listview which is horizontally arranged. 每行是一个水平排列的列表视图。

The data for each listview consists of the strings split using a regex. 每个列表视图的数据由使用正则表达式拆分的字符串组成。

One with no match, up to three if one match is found in a line. 一个没有匹配项,如果在一行中找到一个匹配项,则最多三个。

There is a viewmodel (RunHI) per chunk which has a IsMatch property. 每个块都有一个具有IsMatch属性的视图模型(RunHI)。

When that is true, the background is set to yellow by a datatrigger. 如果是这样,则数据触发将背景设置为黄色。

https://gallery.technet.microsoft.com/WPF-Highlight-Matching-71ad5a04 https://gallery.technet.microsoft.com/WPF-Highlight-Matching-71ad5a04

The sample works with a fixed list of strings but you can readallines https://docs.microsoft.com/en-us/dotnet/api/system.io.file.readalllines?view=netframework-4.8 into an array and foreach that. 该示例使用固定的字符串列表,但您可以将https://docs.microsoft.com/zh-cn/dotnet/api/system.io.file.readalllines?view=netframework-4.8读入数组,并进行遍历。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM