Reputation: 1005
I have a .net2/c# application. It receives data from a socket, formats and displays in a richtextbox control. The communication happens in a seperate thread. The received data is added to a queue that the display function extracts. Quite some heavy duty formatting is done- sorting, coloring etc. The Display function is in the main thread. What I have observed is when there is lot of data to display the whole computer freezes. The toolbar button to abort the display or for that matter the ALT-TAB to switch to another app doesnt work either. I managed to open the task manager on the top of the app and the cpu consumption is only about 25% ( the task manager itself appears to run slow). Any ideas on what might be causing this ? Thanks in advance.
Upvotes: 0
Views: 1440
Reputation: 8138
It is a big error to output log data directly to the GUI.
1.)
You should write your log data in one thread into an intermediate buffer (e.g. an ArrayList) and in the GUI thread set a timer that checks once a second if there is something to be written. Obviouskly you must lock {}
the intermediate buffer wherever you access it.
2.) Additionally there is a severe problem in the RTF control itself. It has the worst performance in the .NET framework.
I wrote an article how to make the RichTextBox 120 times faster here: C# RichEditBox has extremely slow performance (4 minutes loading) SOLVED
Upvotes: 0
Reputation: 1099
The display function that formats the data I suppose it dequeues the data. Is this done on a separate thread? You might consider to do that, if you did not do it already At what point to you actually set the text in the richtextbox? Have in mind that in a multithread environement, any operations that operate on the UI need to be done on the UI thread (InvokeRequired)
Upvotes: 1