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

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

问题描述

好吧,这是一个容易的:

Alright, this is an easy one:

  • 有什么的区别 Application.ThreadException
    AppDomain.CurrentDomain。 UnhandledException

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

我是否需要同时处理?

谢谢!

推荐答案

Application.ThreadException是特定于Windows窗体。的WinForms运行事件处理程序来响应发送给它的Windows消息。例如Click事件,我敢肯定,你认识他们。如果这样的事件处理程序抛出一个异常,然后有一个备用站,​​捕获该异常的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.

这逆止触发<一href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception%28v=vs.110%29.aspx">Application.ThreadException事件。如果不重写,用户将得到一个<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.threadexceptiondialog%28v=vs.110%29.aspx">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.

您可以通过调用<一个禁止此行为href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setunhandledexceptionmode%28v=vs.110%29.aspx">Application.SetUnhandledExceptionMode()在Program.cs中的Main()方法。如果没有这种逆止器的地方,平常的事情发生了,当一个线程未处理的异常死亡:<一href="http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception%28v=vs.110%29.aspx">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天全站免登陆