2013-08-16 54 views
0

我有一個WPF應用程序,我在其中添加一些頂層,捕獲所有錯誤處理。我處理DispatcherUnhandledException事件,像這樣:試圖在DispatcherUnhandledException上顯示一個對話框

private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) 
    { 
     if (_isHandlingError) 
     { 
      _log.Error("Critical unhandled error", e.Exception); 
      e.Handled = true; 
      return; 
     } 

     _isHandlingError = true; 
     var vm = _windsorContainer.Resolve<ErrorReporterViewModel>(); 

     Dispatcher.Invoke(() => 
     { 
      vm.Details = FailureMessageBuilder.CreateContent(e.Exception); 
      var view = new ErrorReporterView { DataContext = vm }; 

      view.Show(); 
     }); 

     e.Handled = true; 

     NotifyOfException(e.Exception, vm.Description); 

     _isHandlingError = false; 
    } 

的問題是,在調用顯示()(或ShowDialog的)永遠不會返回,並且永遠不會顯示錯誤對話框。

可能是什麼問題?

+1

你有沒有調試呢? –

+0

也許不是我知道如何甚至使用調試器..不知道如何使用調試器..什麼是滑稽的... – MethodMan

+0

只是澄清 - 事件觸發,處理程序被調用。但是對Show的調用永遠不會返回。 – Avram

回答

0

您是否已將您的活動附加到應用程序中?

cApp.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException); 
       cApp.InitializeComponent(); 
       cApp.Run(new MainWindow()); 

然後

private static void Dispatcher_UnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) 
     { 
...e.Exception.Message 
} 
+0

只是爲了澄清 - 事件觸發,處理程序被調用。但是對Show的調用永遠不會返回。 – Avram