2016-07-20 8 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(); })); 
関連する問題