"方法是不支持"试图调用一个委托时出错 [英] "Method is not supported" error when trying to invoke a delegate

查看:128
本文介绍了"方法是不支持"试图调用一个委托时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数运行(字符串,字符串[]),我想在一个单独的线程中运行,所以我使用的是委托和的BeginInvoke

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);
}

不过,我得到一个 NotSupportedException异常是未处理由用户code 与消息不支持指定的方法为代表的的BeginInvoke()方法。这是怎么回事了?

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?

我使用Silverlight 4.0和VS2010。

I am using Silverlight 4.0 and VS2010.

推荐答案

异步Delegate.BeginInvoke不适用于在Silverlight中的代表。

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

您应该使用 BackgroundWorker的,而不是为异步运行任何东西。

You should use a BackgroundWorker instead to run anything asynchronously.

这篇关于&QUOT;方法是不支持&QUOT;试图调用一个委托时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆