在Silverlight中,你如何判断是否是code运行在UI线程与否?线程、如何判断、Silverlight、UI

2023-09-04 10:34:23 作者:你眼瞎,撞我心

基本上我需要知道是否我需要可以Dispatcher.BeginInvoke,或者如果它是没有必要的。

Basically I need to know whether I need to can Dispatcher.BeginInvoke or if it's not needed.

感谢。

推荐答案

您可以使用 Dispatcher.CheckAccess 方法。如果你在同一个线程的UI调度它返回true,否则为假

You can use the Dispatcher.CheckAccess method. It returns true if you're on the same thread as the UI dispatcher, and false otherwise