如何为线程设置进度条 [英] how to set a progress bar for a thread
本文介绍了如何为线程设置进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一个帖子中创建了一个很长的过程......就像这样
i am created a long process in a thread ....like this
private void task1()
{
//a long process i don't know when this process end.
}
按钮点击_________________________________
on button click________________________________________
Thread longprocess = new Thread(task1);
longprocess.IsBackground = true;
longprocess.Start();
如何为此设置进度条线程......
How can i set a progress bar for this thread......
推荐答案
而不是线程
,使用BackgroundWorker
:
http://www.dotnetperls.com/backgroundworker [ ^ ]
http://msdn.microsoft。 com / en-us / library / system.componentmodel.backgroundworker.aspx [ ^ ]
如果您添加了BackgroundWorker
,则可以使用ProgressBar
:
http://www.dotnetperl s.com/progressbar [ ^ ]
Hi,
Instead of aThread
, use aBackgroundWorker
:
http://www.dotnetperls.com/backgroundworker[^]
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx[^]
If you added aBackgroundWorker
, you can use aProgressBar
:
http://www.dotnetperls.com/progressbar[^]
检查此链接。这对你有所帮助。链接: http://bytes.com/topic/c-sharp/answers/ 566571-changing-progressbar-seperate-thread [ ^ ]
Check this link. It will be helpful for you. Link : http://bytes.com/topic/c-sharp/answers/566571-changing-progressbar-seperate-thread[^]
你可以试试这个:
Hi,
you can try this :
/// <summary>
/// Update the work item state counts.
/// </summary>
private void RefreshCounts()
{
if (this.InvokeRequired)
{
MethodInvoker mi = new MethodInvoker(RefreshCounts);
this.BeginInvoke(mi);
}
else
{
lock (this)
{
progressBar1.Value = ProgressDownload;
}
}
}
godd运气
jeremy
godd luck
jeremy
这篇关于如何为线程设置进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文