2016-07-20 68 views
0

我有下面的代码打开一个对话框,向用户指示应用程序正在另一个线程中处理,然后一旦它接收到LoadCompletedEvent就会关闭窗口。但是,我总是得到以下错误,并不确定它指的是什么。WPF System.Reflection.TargetParameterCountException参数计数不匹配

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

我假设,你正在使用MahApps? – lokusking

+0

我正在使用MahApps。新对象[2]不起作用,但是当进行进一步调试时,它在metroProgressWindow.ShowDialog()上失败。其中不包含任何参数 – jkratz55

+0

ShowDialog不接受任何参数的事实完全不相关:它激活了窗口的逻辑,问题在于Action没有参数。 –

回答

0

我认为问题是由在BeginInvokenull参数引起的。 尝试没有它的例子:

Dispatcher.BeginInvoke(DispatcherPriority.Normal, 
    new Action(() => { this.Close(); }));