如何从一个BackgroundWorker线程中更新标签吗? [英] How do I update a Label from within a BackgroundWorker thread?
本文介绍了如何从一个BackgroundWorker线程中更新标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用的WinForms,我会在我的 bg_DoWork
方法做到了这一点:
When I used WinForms, I would have done this in my bg_DoWork
method:
status.Invoke(new Action(() => { status.Content = e.ToString(); }));
status.Invoke(new Action(() => { status.Refresh(); }));
然而,在我的WPF应用程序,我得到一个错误,指出调用
不存在标签
。
However in my WPF application I get an error saying that Invoke
does not exist for Label
.
任何帮助,将不胜感激。
Any help would be appreciated.
推荐答案
这将帮助你。
要同步执行:
Application.Current.Dispatcher.Invoke(new Action(() => { status.Content = e.ToString(); }))
异步执行:
Application.Current.Dispatcher.BeginInvoke(new Action(() => { status.Content = e.ToString(); }))
这篇关于如何从一个BackgroundWorker线程中更新标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文