c# - 尝试调用委托(delegate)时出现 "Method is not supported"错误

标签 c# .net multithreading silverlight delegates

我有一个函数 Run(string, string[]) 我想在一个单独的线程上运行,所以我使用了一个委托(delegate)和 BeginInvoke:

private Func<string, string[], Stack<StackItem>> runner;

public MainPage()
{
    runner = Run;
}

private void btnStep_Click(object sender, RoutedEventArgs e)
{
    // snip
    runner.BeginInvoke(tbCode.Text, GetArgs(), null, null); // Exception here
    // snip
}

private Stack<StackItem> Run(string program, string[] args)
{
    return interpreter.InterpretArgs(parser.Parse(lexer.Analyse(program)), args);
}

但是,我得到一个 NotSupportedException was unhandled by user code 消息 Specified method is not supported for the BeginInvoke() method委托(delegate)的。出了什么问题?

我正在使用 Silverlight 4.0 和 VS2010。

最佳答案

异步 ​​Delegate.BeginInvoke 不适用于 Silverlight 中的委托(delegate)。

你应该使用 BackgroundWorker instead异步运行任何东西。

关于c# - 尝试调用委托(delegate)时出现 "Method is not supported"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3516161/

相关文章:

c# - ASP.NET 母版页的动态变化

c# - C#中如何访问内部对象的属性

c# - RestSharp - 如何处理非 200 响应? RestClient 在执行时抛出异常

c# - .Net 3.5 到 4 的迁移导致应用程序变慢

java - 如何以正确的方式编写单例?

c++ - 使用 2 个线程的代码运行速度比使用 1 个线程慢 6 倍

c# - 双击 ListView 中的项目 C#

c# - 在 WPF 中使用开放 XML 根据单元格值对单元格着色

c# - 构建可扩展数据模型,EF 4

java - Android 上 rxjava 的默认调度器