尝试调用委托时出现"方法不受支持"错误

Cal*_*ers 4 .net c# silverlight multithreading delegates

我有一个函数Run(string, string[]),我想在一个单独的线程上运行,所以我使用委托和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);
}
Run Code Online (Sandbox Code Playgroud)

不过,我得到一个NotSupportedException was unhandled by user code与消息Specified method is not supportedBeginInvoke()委托的方法.出了什么问题?

我正在使用Silverlight 4.0和VS2010.

Gon*_*ing 7

异步Delegate.BeginInvoke不适用于Silverlight中的代理.

您应该使用BackgroundWorker来异步运行任何内容.

  • 真?我想知道为什么不允许`BeginInvoke()`? (3认同)