哪个.config元素影响异常处理,UnhandledExceptionMode设置为UnhandledExceptionMode.Automatic?

Mar*_*own 9 c# configuration winforms

我有一个Windows窗体应用程序,在程序启动时有这个代码:

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic);
Run Code Online (Sandbox Code Playgroud)

UnhandledExceptionMode.Automatic的MSDN文档中,它声明:

自动 - 将所有异常路由到ThreadException处理程序,除非应用程序的配置文件另行指定.

有没有人确切知道配置文件中哪个元素/属性会影响此设置?

Jos*_*shL 5

您可以在配置文件中添加JitDebugging部分,如下所示:

<configuration>
  <system.windows.forms jitDebugging="true"/>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这相当于将UnhandledExceptionMode设置为UnhandledExceptionMode.ThrowException(顺便说一下,如果运行附带调试器的应用程序,则会自动启用此选项).

请注意,这UnhandledExceptionMode.Automatic是.Net使用的默认值,除非您另行指定; 据我所知,将未处理的异常模式显式设置为自动的唯一原因是,如果要撤消先前将其更改为其他内容的调用.请注意,如果将其设置为"自动"以外的其他值,则不会读取配置文件设置.

请注意,如果将ThreadException附加到当前AppDomain,结果将自动为您将UnhandledExceptionMode设置为UnhandledExceptionMode.CatchException.

  • 我终于得到了更深入的研究,虽然这是具有效果的设置,但它是否有效果有点复杂.DebuggableAttribute上的IsJITDebugLaunchSetting标志的值以及以下两个注册表项也有依赖性:HKLM\Software\Microsoft\.NETFramework -DbgJITDebugLaunchSetting和DbgManagedDebugger. (2认同)