这与上一个问题有关。
我现在想了解的是如何防止 UI 线程异常终止应用程序,而非 UI 异常则不能。
作为参考,请参阅此示例。
最重要的是,在这种情况下,我希望能够“静默”地终止进程——而不显示询问我是否要发送错误报告的 Windows 对话框。
这是我的 AppDomain UnhandledExceptionHandler:
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
// Maybe do some logging here if allowed
}
catch
{
}
// then just terminate the application
Application.Exit();
}
更新
鉴于此答案中的评论,我想澄清一下,最重要的是,我想了解更多有关使 UI 线程能够及早通过该Application.ThreadException
机制捕获未处理异常的机制的信息。以及这种行为是否可以在非 UI 线程上实现。