문제

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