2
在WinForms中是否有相当于Control.InvokeRequired
的SilverLight?invoke需要silverlight吗?
我已经发现的WinForms调用相当于Control.Dispatcher.BeginInvoke
但我不能找到什么样InvokeRequired
在WinForms中是否有相当于Control.InvokeRequired
的SilverLight?invoke需要silverlight吗?
我已经发现的WinForms调用相当于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();
}
感谢下列扩展方法是非常有用的,这看起来帮助 –
你可以排名的答案了 – ahmedsafan86
你的意思是这样的? –