Question

I have a function that simply fills a progress bar.

private void FillProgressBar(ProgressBar bar, Color c, int percent)
{
    int steps = 10;
    bar.set_Value(0);
    for (int i = 0; i < percent / steps; i++)
    {
        System.Threading.Thread.Sleep(100);
        bar.set_Value((i+1)*10) + bar.get_Value());
        this.Refresh();
    }
}

I summon it from the gui thread (not multi threading) and it's purpose is to slowly fill the bar.

But it doesn't seem to be doing it, although the value does raise.

Any suggestions on how to update a specific control or the whole form? PS : as you can see, this.Refresh() didn't work either.

Was it helpful?

Solution

try using

Application.DoEvents();

After updating the progress bar.

more on DoEvents here

OTHER TIPS

Your current code don't let the main message loop execute and so it'll block all messages including WM_PAINT ones...

You shouldn't do that, use a thread, use a timer : don't block the UI.

And don't use Application.DoEvents it's bad programming practice and shouldn't even exists.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top