我有一个函数 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/