I am using .Net 4.0 and VS2010.
My program is simply a multi-threaded get request sender which update a bindingList and display the list via DataGridView. The datagridview is in virtual mode. Moreover, I make a textbox and status bar to display the status of requests, one request normally adds 4-5 lines to the textbox and changes the number in the status bar.
The workload remains the same, one request per two seconds. The request is fast and only one request is standing out most of the time. New request thread is called by the last old request thread. The UI is updated a few times per thread using begininvoke and delegate.
MyInvoke mi = new MyInvoke(change);
this.BeginInvoke(mi, new Object[] { true, "Row " + pos + " standing by...", (pos + 1),0 });
I display the whole 3000 requests on the datagridview at the beginning with memory usage 30MB. When the 2XXX request is reached with memory usage 4XMB, I can see the status bar number and textbox updated slower and slower. For example, 2000->2001->2002->2003 becomes 2000->2003.
If I select the application window, sometimes the whole UI would even freeze. My datagridview is fixed on a few rows with virtual mode. I believe it is the problems of the UI thread. When it freezes, I can wait until all requests are done and everything becomes smooth again.
Any thoughts on what is happening?
Finally, I figured out why it was so slow. Noob like me might easily make this kind of error.
The large number of begininvoke I used during the thread does affect but it is not significant enough to freeze the UI thread.
The heavy workload is mainly bought by the below code which assign whole of the text to the textbox every time
The following code could solve it