SilverLight 中是否有相当于 Control.InvokeRequired
的东西?在 Winforms 中?
我已经发现 Winforms Invoke 相当于 Control.Dispatcher.BeginInvoke
但我找不到像 InvokeRequired
这样的东西
最佳答案
以下扩展方法非常有用
public static bool InvokeRequired(this FrameworkElement element)
{
return !element.Dispatcher.CheckAccess();
}
public static void Invoke(this FrameworkElement element, Action action)
{
if (element.InvokeRequired())
{
using (AutoResetEvent are = new AutoResetEvent(false))
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
action.Invoke();
are.Set();
});
are.WaitOne();
}
}
else
action.Invoke();
}
关于silverlight - 在 Silverlight 中需要调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13207933/