繁体   English   中英

WPF中的TargetParameterCountException

[英]TargetParameterCountException in WPF

TargetParameterCountException:参数计数不匹配。

请问这是怎么回事?

方法完成后,将引发此错误。

我已经尝试过其他一些话题,但是我的情况有所不同。

有什么线索吗?

我正在使用此Dispatcher,因为我遇到了跨线程问题。

void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
    if (backgroundWorker.CancellationPending == true)
    {
        e.Cancel = true;
        return;
    }

    e.Result = ...;

    Dispatcher.BeginInvoke(DispatcherPriority.Normal,
        (RunWorkerCompletedEventHandler)delegate
        {
            image1.Source = (BitmapImage)e.Result;
        });
}

RunWorkerCompletedEventHandler委托期望您不提供(或使用)的参数,可以将其更改为Action

Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate
{
    image1.Source = (BitmapImage)e.Result;
});

如果必须使用RunWorkerCompletedEventHandler (毫无意义),则可以调用相应的BeginInvoke重载,并提供一个由两个对象组成的空数组,分别表示发送方和事件参数:

Application.Current.Dispatcher.BeginInvoke((RunWorkerCompletedEventHandler)delegate
{
    image1.Source = (BitmapImage)e.Result;
}, DispatcherPriority.Normal, new object[2]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM