I have a problem of UI freeze with my application in C# which basically fetch datas, compute stats on these datas, wait for 4 seconds and do it again and again.
Following http://msdn.microsoft.com/en-us/libr...undworker.aspx
I used 2 background workers, 1 to fetch and the other one to compute stats. It then returns to the main thread which shows computed stats in a datagridview ( but I have the same problem with a textBox). In _RunWorkerCompleted functions, I update the UI.
The problem is that UI freezes during the fetch and computing, then un-freezes during the 4 seconds ( I can barely move the window but computed stats are shown) and it freezes again and again.. I was looking to solve this problem with background workers...
What do I do wrong ? Can you help me ? Here is the important portion of code :
****************************
Expand|Select|Wrap|Line Numbers
- while (true)
- {
- backgroundWorkerFetchData.RunWorkerAsync((String)one);
- while (backgroundWorkerFetchData.IsBusy)
- {
- Application.DoEvents();
- }
- backgroundWorkerComputeStats.RunWorkerAsync((int)10);
- while (backgroundWorkerComputeStats.IsBusy)
- {
- Application.DoEvents();
- }
- Thread.Sleep(4000);
- }
Thanks !