ProgressBar Does Not Refresh

  • Thread starter Thread starter Nick Carter
  • Start date Start date
N

Nick Carter

I have a progressbar which gets updated with the following code:-

for(int value=0; value < 100; value++)
{
progressBar1.Value = progressBar1.Value + 1;
progressBar1.Refresh();
System.Threading.Thread.Sleep(100);
}

The progressbar is updated just fine. However, if I Alt+Tab to another
application and then come back to my original application then the user
interface goes completely unresponsive until the for loop has ended. How can
I get the user interface to continue to be updated after the focus has
returned to my application ?

Nick Carter
 
If you don't want a thread to do the loop, use Application.DoEvents() before
every sleep, however, if you flick to your app while it is sleeping, it will
only correct the display after it wakes up, but you should not be aware of
this if the sleep is short (like in your case, 100 ms).
 
Chris,

That works just great. Thanks.

Nick

Chris Botha said:
If you don't want a thread to do the loop, use Application.DoEvents() before
every sleep, however, if you flick to your app while it is sleeping, it will
only correct the display after it wakes up, but you should not be aware of
this if the sleep is short (like in your case, 100 ms).
 
Back
Top