ProgressBar resets at 60%

后端 未结 4 795
花落未央
花落未央 2021-01-13 23:09

I have this code:

for(int k = 0; k<11; k++)
{
    pBar.Maximum = 10;
    pBar.Value = k;
    if (pBar.Maximum == k)
        pBar.Value = 0;
}
4条回答
  •  忘掉有多难
    2021-01-13 23:51

    First: there is no any reason to assign pBar.Maximum on every interarion. Just do:

    pBar.Maximum = 10;
    for(int k = 0; k<11; k++)
    {
       pBar.Value = k;
       if (pBar.Maximum == k)
          pBar.Value = 0;
    }
    

    Second: your code result in blocking iteration. There is no way it could ever behave correctly. Use multi-threading and change the progress value based on some event,tick whatever, not in loop, as it's done here.

提交回复
热议问题