简体   繁体   English

进度栏不起作用

[英]Progress bar isn't working

I'm trying to use 4 progress bars in a 4 step process. 我试图在4个步骤的过程中使用4个进度条。 Essentially the progress bars are being used because the project takes a LONG time to run, using a single progress bar with the (divide by ten) that normally is used would mean that the progress bar would gain 1 sliver every 20 minutes. 本质上,正在使用进度条,因为该项目需要很长时间才能运行,使用单个进度条(通常使用(除以十))将意味着进度条每20分钟获得1条。 (too long.) (太长。)

Here is the code: 这是代码:

backgroundWorker1.ReportProgress(a++);

if (a == 100)
{
    backgroundWorker2.ReportProgress(b++);
    a = 0;
}

if (b == 100)
{
    backgroundWorker3.ReportProgress(c++);
    b = 0;
}

if (c == 100)
{
    c = 0;
    d = 25;
}

backgroundWorker4.ReportProgress(d);

The problem is, the first progress bar goes to about 99% and stops, the 2nd bar doesn't move at all but the process is still running. 问题是,第一个进度条达到约99%并停止,第二个进度条根本不动,但进程仍在运行。

Try to do parameter increment before passing to method. 尝试在传递给方法之前进行参数递增。 In C# increment operator can appear before and after its operand. 在C#中, 增量运算符可以出现在其操作数之前和之后。 When you do (a++) it is postfix increment operation. 当您执行(a ++)时,它是后缀增量操作。 Result of this operation is value of a before it was incremented. 该操作的结果是递增a 之前的a值。 Thus maximum value passed to ReportProgess will be 99 instead of 100. If you change increment operation to (++a), which is prefix increment, then result of operation will be value of a after increment: 因此,传递给ReportProgess最大值将是99,而不是100。如果将增量运算更改为(++ a),即前缀增量,则运算结果将是after增量的值:

backgroundWorker1.ReportProgress(++a);

Same with other calls. 与其他通话相同。 Btw last reporting is strange - value of d changed only once. 顺便说一句,最后一次报告很奇怪d值仅更改了一次。 Maybe you should use d += 25 instead? 也许您应该改用d += 25

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM