System.Windows.Threading.Dispatcher和WinForms? [英] System.Windows.Threading.Dispatcher and WinForms?

查看:89
本文介绍了System.Windows.Threading.Dispatcher和WinForms?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否进行 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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