Application.ThreadException和AppDomain.CurrentDomain.UnhandledException有什么区别? [英] What's the difference between Application.ThreadException and AppDomain.CurrentDomain.UnhandledException?

查看:146
本文介绍了Application.ThreadException和AppDomain.CurrentDomain.UnhandledException有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这很简单:


  • 应用程序有什么区别? .ThreadException
    AppDomain.CurrentDomain.UnhandledException

  • What's the difference between Application.ThreadException and
    AppDomain.CurrentDomain.UnhandledException?

我是否需要处理?

谢谢!

推荐答案

Application.ThreadException特定于Windows窗体。 Winforms运行事件处理程序以响应Windows发送的消息。例如,点击事件,我确定你知道他们。如果这样的事件处理程序引发异常,那么在Winforms消息循环中有一个后台停止捕获该异常。

Application.ThreadException is specific to Windows Forms. Winforms runs event handlers in response to messages sent to it by Windows. The Click event for example, I'm sure you know them. If such an event handler throws an exception then there's a back-stop inside the Winforms message loop that catches that exception.

该backstop触发 Application.ThreadException 事件。如果不覆盖它,用户将获得一个 ThreadExceptionDialog 。这允许他忽略异常并继续运行你的程序。不是一个好主意btw。

That backstop fires the Application.ThreadException event. If you don't override it, the user will get a ThreadExceptionDialog. Which allows him to ignore the exception and keep running your program. Not a great idea btw.

您可以通过调用 Application.SetUnhandledExceptionMode()。没有这个backstop就行了,当一个线程从一个未处理的异常死机时,通常会发生: AppDomain.UnhandledException 触发并程序终止。

You can disable this behavior by calling Application.SetUnhandledExceptionMode() in the Main() method in Program.cs. Without that backstop in place, the usual thing happens when a thread dies from an unhandled exception: AppDomain.UnhandledException fires and the program terminates.

Fwiw:ThreadException是一个非常糟糕的名字选择。它与线程无关。

Fwiw: "ThreadException" was a very poor name choice. It has nothing to do with threads.

这篇关于Application.ThreadException和AppDomain.CurrentDomain.UnhandledException有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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