如何准确地刷新进度 [英] How to refresh ProgressBar accurately

查看:100
本文介绍了如何准确地刷新进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了使用for循环2次短的方法:

I wrote a short method that uses a for loop 2 times:

progressBar1.Minimum = 1;
progressBar1.Maximum = 1000000;
progressBar1.Step = 1;

for (int idx = 1; idx < 1000000; idx++)
{    
    progressBar1.PerformStep();
}

Thread.Sleep(2000);
progressBar1.Invalidate();
this.Update();

progressBar1.Value = 1;
for (int idx = 1; idx < 1000000; idx++)
{
    progressBar1.PerformStep();
}



我的问题是:一号通,当值获得1000000实际的彩色条仅
横跨显示约50-75%,但从来没有100%的跨越,即使值已达到最大值。

My question is this: on the 1st pass, when the value gets to 1000000 the actual colored bar only displays about 50-75% across, but never 100% across, even though the value has reached the maximum.

这是独一无二的多次使用进度的一种方法。

This is unique to using the progressbar multiple times in one method.

我怎样才能得到实际的彩色条获得到最后?

How can I get the actual colored bar to get to the very end?

(显然它是一个缓冲的事情吗?)

(Apparently its a buffering thing?)

推荐答案

现在的问题是,你阻止您的UI线程。不要那样做。在后台线程执行所有的长时间运行的任务(如的BackgroundWorker )和元帅回UI线程更新进度条( BackgroundWorker的使得这很琐碎)...然后就一切正常了。

The problem is that you're blocking your UI thread. Don't do that. Perform all the long-running tasks in a background thread (e.g. a BackgroundWorker) and marshal back to the UI thread to update the progress bar (BackgroundWorker makes this pretty trivial)... then all should be well.

这篇关于如何准确地刷新进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆