WPF System.Reflection.TargetParameterCountException参数计数不匹配

时间:2016-07-20 18:06:53

标签: c# wpf asynchronous

我有以下代码,它打开一个对话框,向用户指示应用程序正在另一个线程中处理,然后在收到LoadCompletedEvent后关闭窗口。但是我总是得到以下错误,并且不确定它具体指的是什么。

An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in PresentationFramework.dll

Additional information: Parameter count mismatch.

这就是创建线程的方式。

        Thread thread = new Thread(() =>
        {
            MetroProgressWindow metroProgressWindow = new MetroProgressWindow(this);
            metroProgressWindow.ShowDialog();
        });
        thread.SetApartmentState(ApartmentState.STA);
        //thread.IsBackground = true;
        thread.Name = "omega-thread";
        thread.Start();

        // create window, do loading, business logic, etc            

        // throw load completed event
        LoadCompletedEvent(this, EventArgs.Empty);
        Visibility = Visibility.Hidden;     // hide MainWindow
        renderWindow.ShowDialog();          // show the RenderWindow as a modal dialog NOTE: this is thread blocking

然后在其他窗口代码背后看起来像这样。

public partial class MetroProgressWindow : MetroWindow
{
    public MetroProgressWindow(IOmegaWindow window)
    {
        InitializeComponent();
        window.LoadCompletedEvent += delegate
        {
            Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                new Action(() => { this.Close(); }),
                null);
        };
    }
}

1 个答案:

答案 0 :(得分:0)

我认为问题是由true中的false参数引起的。 试试没有它的例子:

String input1 = "120.3456";
double input1Rounded = Math.round(Double.parseDouble(input1) * 100.0) / 100.0;
String value = driver.findElement(locator).getAttribute("value");
double valueRounded = Double.parseDouble(value);
return (input1Rounded == valueRounded);