C# 进度条运行时间少于定义时间-继续上一篇文章
这是我之前的帖子: 所有的答案都是,我不需要将毫秒除以100,当我尝试这个解决方案时,进度条运行变慢,不像第一次它运行变快,但我认为我需要将毫秒除以100,以便设置进度应运行的总100%中的每1%。 例如,如果我想让我的进度条运行10秒,那么我除以10000/10,每1%(或计时器滴答声)将需要100毫秒,因此即使我将其配置为100,它仍然会变快C# 进度条运行时间少于定义时间-继续上一篇文章,c#,winforms,C#,Winforms,这是我之前的帖子: 所有的答案都是,我不需要将毫秒除以100,当我尝试这个解决方案时,进度条运行变慢,不像第一次它运行变快,但我认为我需要将毫秒除以100,以便设置进度应运行的总100%中的每1%。 例如,如果我想让我的进度条运行10秒,那么我除以10000/10,每1%(或计时器滴答声)将需要100毫秒,因此即使我将其配置为100,它仍然会变快 void bittwist_progBarEventHandler(object sender, EventArgs e) { this.In
void bittwist_progBarEventHandler(object sender, EventArgs e)
{
this.Invoke((MethodInvoker)delegate { AnimateProgBar((int)sender); });
}
public void AnimateProgBar(int milliSeconds)
{
if (!timerProgress.Enabled)
{
this.Invoke((MethodInvoker)delegate { pbStatus.Value = 0; });
timerProgress.Interval = milliSeconds / 100;
timerProgress.Enabled = true;
}
}
private void timerProgress_Tick(object sender, EventArgs e)
{
if (pbStatus.Value < 100)
{
pbStatus.Value += 1;
pbStatus.Refresh();
}
else
{
timerProgress.Enabled = false;
}
}
void bittwist\u progBarEventHandler(对象发送方,事件参数e)
{
Invoke((MethodInvoker)委托{AnimateProgBar((int)sender);});
}
公共void AnimateProgBar(整数毫秒)
{
如果(!timerProgress.Enabled)
{
this.Invoke((MethodInvoker)委托{pbStatus.Value=0;});
timerProgress.Interval=毫秒/100;
timerProgress.Enabled=true;
}
}
私有void timerProgress_Tick(对象发送方,事件参数e)
{
如果(pbStatus.Value<100)
{
pbStatus.Value+=1;
pbStatus.Refresh();
}
其他的
{
timerProgress.Enabled=false;
}
}
例如,对于
毫秒==10000
进度条仅运行7秒比定义的时间少/多
您的确切意思是什么?例如:我希望它运行1秒,它运行100/0.1秒?并显示调用AnimateProgBar
的代码我希望运行进度条的毫秒数。我看不出此代码有任何问题。它在我的机器上按预期运行:当给定10000毫秒时,progressbar的填充时间不少于10秒。这就是为什么我建议再次检查传递到AnimateProgBar
中的值。尝试将对此方法的每次调用硬编码为AnimateProgBar(10000)
,并检查结果。此外,检查是否没有其他方法正在访问progressbar和timer。