在Vista上,我遇到了应用程序崩溃处理程序的问题.基本上,如果出现SEH无法捕获的意外情况,我会在弹出窗口中显示"应用程序停止工作",blablabla,"关闭程序/调试程序" - 也就是说,在我禁用错误报告后使用系统控制面板.启用错误报告后,您将获得一个任务对话框,可以在线搜索解决方案,关闭,调试.
如果它发生在自动化工具中,这不是那么有趣,我想知道是否有一种方法可以完全摆脱它,读取,如果我的应用程序崩溃,它只是崩溃到命令行或消失但没有提出对话框.
我在这篇文章中读过,为了避免"程序停止工作"对话框,我需要从AppDomain中捕获未处理的异常.
public Form1()
{
///Code
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
///more code
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var excep = e.ExceptionObject;
//Writing the exception to log file with the stack flow
Logger.Logger.LogException("UNHANDLED EXCEPTION:"+Environment.NewLine +excep.ToString(), this);
//Terminate the logger (manual event waiting for file write to finish)
Logger.Logger.Terminate();
Environment.Exit(1);
}
Run Code Online (Sandbox Code Playgroud)
但是当我被吸入异常时.我可以看到它写在日志上,但应用程序显示"程序停止工作"对话框.它可以由Logger.Terminate线路引起吗?(再次 - terminate命令等待,直到所有日志都写入日志文件)