问题描述
是否进行 System.Windows.Threading.Dispatcher
在WinForms
应用程序的UI线程上?
如果是,为什么?它来自WindowsBase.dll,它似乎是一个WPF
组件.
如果没有,如何将工作单元重新调用到UI线程上?我发现 Control.BeginInvoke()
,但是创建仅引用原始线程的控件似乎很笨拙.
即使在WinForms应用中,您也可以使用Dispatcher
.
如果您确定要使用UI线程(例如在button.Click处理程序中),则Dispatcher.CurrentDispatcher
为您提供UI线程分派器,您以后可以像往常一样使用它从后台线程分派到UI线程. /p>
Does a System.Windows.Threading.Dispatcher
work on the UI-thread of a WinForms
application?
If yes, why? It is coming from WindowsBase.dll which seems to be a WPF
component.
If not, how can I invoke work units back onto the UI-thread? I've found Control.BeginInvoke()
, but it seems clumsy to create a control only to reference the originating thread.
You can use Dispatcher
even in a WinForms app.
If you are sure to be on a UI thread (e.g. in an button.Click handler), Dispatcher.CurrentDispatcher
gives you the UI thread dispatcher that you can later use to dispatch from background threads to the UI thread as usual.
这篇关于System.Windows.Threading.Dispatcher和WinForms?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!