如何通过Dispatcher.Invoke处理进度条 [英] How to handle progressbar over Dispatcher.Invoke
问题描述
当我拨打
Hi,
My progressbar get stuck when i call
Dispatcher.Invoke
时,我的进度条卡住了。
请考虑以下代码段。
.
Please consider following code snippet.
private void DoWork()
{
Progressbar.show();//Displays progress bar
System.Windows.Application.Current.Dispatcher.Invoke((Action)delegate
{
Function1();//Takes 1 min to execute
});
Progressbar.close();//Closes progress bar
}
我有DoWork()方法显示进度条,然后在那里是用于修改UI控件的Dispatcher.Invoke方法。
由于Dispatcher.Invoke中的Fin1 Function1()需要很长时间才能完成。因此,在执行Dispatcher.Invoke时,它会停止进度条的进度。
请告诉我如何显示进度条,以便在执行Dispatcher时不会停止.Invoke
I have DoWork() method which displays progressbar and after that there is Dispatcher.Invoke method for modifying UI control.
As finction Function1() inside Dispatcher.Invoke takes long time to finish. So while executing Dispatcher.Invoke, it stops progress of progressbar.
Please tell me how I shall show progress bar so that it will not stop while executing Dispatcher.Invoke
推荐答案
请参阅我对该问题的评论。我没有直觉可以解释你做错了多少以及解决方案无关紧要解决方案1.
只看我过去的回答和那里引用的答案: 主线程上的.NET事件 [ ^ ]。
你迷路太多,以至于我不能确定你能理解我的解释,但是如果有疑问,请尝试一些后续问题。
-SA
Please see my comment to the question. I have no gut to explain how wrong is what you do and how irrelevant is the "solution" Solution 1.
Just see my past answer and the answers referenced there: .NET event on main thread[^].
You are lost so much that I cannot be sure that you can understand my explanations, but please just try, ask some follow-up questions in case of doubt.
—SA
当你必须显示进度条并在后台做一些工作时,而不是使用后台工作者。
见链接
https://msdn.microsoft.com/en-us/library/cc221403(v=vs.95) .aspx
Instead of Use Background Worker when u have to show progressbar and do some work in background.
See link
https://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx
嗨试试这个
Hi Try this
Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
{
string text = textbox1.Text;
});
这篇关于如何通过Dispatcher.Invoke处理进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!