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.

有帮助吗?

解决方案

try using

Application.DoEvents();

After updating the progress bar.

more on DoEvents here

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top