I'm developing an MDI application in C#.NET using Visual Studio 2008
When the user clicks a button on a child window a time-consuming calculation commences. It takes about 20 seconds. Obviously I don't want the user interface locked up for this length of time.
So what Ive done is use a delegate. This performs the calculation and also updates a progress bar on the child window. I've used another delegate within this delegate to update the progress bar
The progress bar updates nice and smoothly as expected. However if I try and click anywhere else on my application the UI locks up and the cursor goes "busy". So something is obviously not working. The time consuming calculation contains several while loops. Ive noticed that if I add "application.doEvents()" in the loops my UI becomes responsive, if a bit sticky. However I don't like this solution. I don't think I should have to add application.doEvents().
I also do writing to a file so not sure if that is the problem
The 2 delegates I use are;
public delegate bool doCalculation(Rectangle selectionRect, int firstBand, int secondBand, string dataType, ProgressBarX theBar);
public delegate bool updateProgressBarDelegate(
rX theBar, int theValue);
Ive attached a code snippet below. The function in OkB_Click() starts off my calculation.
Ive taken out some error checking and simplified it slightly but the structure remains. Im thinking I need another delegate for the code within the while loops possibly?
Can anyone spot why this isn't doing what I want? Thanks.code.txt