currentDomain.UnhandledExcepti ... [英] currentDomain.UnhandledExcepti...

查看:69
本文介绍了currentDomain.UnhandledExcepti ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据库应用程序。我已经处理了 currentDomain.UnhandledException 并将一个新窗口显示为对话框。

但是当出现UnhandledException时,对话框窗口会出现但已冻结。我无法处理它。

I am working in a database application. I have handled the currentDomain.UnhandledException and showing a new window as a dialog.
But when the UnhandledException occurs the dialog window appears but frozen. I cannot deal with it.

Private Sub UnhandledExceptionHandled(sender As Object, e As UnhandledExceptionEventArgs)
      Dim es As Exception = DirectCast(e.ExceptionObject, Exception)
 Writer.WriteLine(es.Message & System.Reflection.MethodBase.GetCurrentMethod().Name)
      Writer.Close()
      Dim Wnd As New ErrorWindow
      Try
          If Wnd.ShowDialog() Then
          ' Do something
          End If
      Catch ex As Exception
      End Try
  End Sub



ErrorWindow 是一个普通窗口。显示后我无法处理。


ErrorWindow is an ordinary window. after showing I cannot deal with.

推荐答案

对于Windows应用程序,您必须在主事件循环中稍早处理所有异常。 WPF和 System.Windows.Forms 都有规定。



要了解如何在 System.Windows.Forms ,请看我过去的答案: http://www.codeproject.com/Answers/139319/Catching-an-Exception#answer2 [ ^ ]。



在WPF中,有一种非常相似的机制。它的用法可能如下所示:

For Windows applications, you have to handle all exceptions just a bit earlier, in the main event loop. Both WPF and System.Windows.Forms have provisions for it.

To see how to do it in System.Windows.Forms, please see my past answer: http://www.codeproject.com/Answers/139319/Catching-an-Exception#answer2[^].

In WPF, there is a very similar mechanism. Its use may look like this:
class MyApplication: Application {

     internal MyApplication() {
         DispatcherUnhandledException += (sender, eventArgs) => {
             ShowException(eventArgs.Exception);
             eventArgs.Handled = true;
         }; //DispatcherUnhandledException
     } //MyApplication

     void ShowException(System.Exception exception) {
         // show exception information
         // if you use some MessageBox or some other window in modal mode,
         // it won't freeze :-)
     }

     // ...

}





-SA


这篇关于currentDomain.UnhandledExcepti ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆