views:

79

answers:

1

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.

+2  A: 

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

You should use a BackgroundWorker instead to run anything asynchronously.

Enough already
Really? I wonder why `BeginInvoke()` is not allowed?
Callum Rogers