“Method is not supported” error when trying to inv

2019-02-17 22:39发布

I have a function Run(string, string[]) which I want to run on a separate thread, so I am using a delegate and 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);
}

However, I get a NotSupportedException was unhandled by user code with a message of Specified method is not supported for the BeginInvoke() method of the delegate. What's going wrong?

I am using Silverlight 4.0 and VS2010.

1条回答
我只想做你的唯一
2楼-- · 2019-02-17 23:06

The asynchronous Delegate.BeginInvoke is not available for delegates in Silverlight.

You should use a BackgroundWorker instead to run anything asynchronously.

查看更多
登录 后发表回答