在SilverLight中有没有等同于Winforms中的Control.InvokeRequired的东西?
我已经发现Winforms Invoke等同于Control.Dispatcher.BeginInvoke,但是我找不到像InvokeRequired这样的东西
发布于 2012-12-06 19:51:16
以下扩展方法非常有用
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();
}https://stackoverflow.com/questions/13207933
复制相似问题