簡體   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