如何获取UI线程的分派器? [英] How do I get the UI thread's Dispatcher?

查看:59
本文介绍了如何获取UI线程的分派器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您没有引用任何UI元素时,是否可以获取UI线程的Dispatcher?

Is there any way to get the UI thread's Dispatcher when you have no reference to any UI elements?

推荐答案

您可以从静态应用程序实例中获取UI Dispatcher:Application.Current.Dispatcher

You can grab the UI Dispatcher from the static application instance: Application.Current.Dispatcher

您可能需要先检查Application.Current是否为null,因为可以在关闭序列期间将其清除.

You may want to check Application.Current for null first, as it can be cleared during a shutdown sequence.

这篇关于如何获取UI线程的分派器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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