SilverLightには、Winformsと同等のものがありControl.InvokeRequired
ますか?
Winforms Invokeはと同等であることがすでにわかりましたControl.Dispatcher.BeginInvoke
が、次のようなものは見つかりません。InvokeRequired
SilverLightには、Winformsと同等のものがありControl.InvokeRequired
ますか?
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();
}