silverlight - 在 Silverlight 中需要调用?

标签 silverlight invoke multithreading begininvoke invokerequired

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/

相关文章:

silverlight - 具有 .net Ria 服务和 SilverlightFX 的 Silverlight 应用程序

silverlight - SL 媒体元素在第一次后不会播放我的 wave 文件

silverlight - 在运行时添加新列

C# PowerShell 远程处理问题 : method or operation not implemented

C# WPF 更新 GUI 并移动网格

c++ - 并发 : Are Python extensions written in C/C++ affected by the Global Interpreter Lock?

java - volatile关键字没有用 当使用synchronized时?

silverlight - Telerik Silverlight RadTreeview 自动刷新

c# - 盲目地使用 InvokeRequired 不是一种不好的做法吗?

java - 系统 loadLibrary 在多线程中使用时挂起