在我的项目中,代码处理未处理的异常,如下所示。
static void FnUnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs _UnhandledExceptionEventArgs)
{
Exception _Exception = (Exception)_UnhandledExceptionEventArgs.ExceptionObject;
OnUnwantedCloseSendEmail(_Exception.Message);
}
我在用OnUnwanted关闭发送电子邮件发送错误报告电子邮件的方法。 OnUnwantedCloseSendEmail 方法的最后一行是应用程序.重新启动();
当这种方法正确工作时,.net框架会显示如下错误提示窗口,并且应用程序不会关闭并重新启动,直到按下退出按钮。
如果没有此提示,我如何退出应用程序当应用程序也冻结时,我该如何应用这种方法。
您可能想查看应用程序.SetUnhandledExceptionMode http://msdn.microsoft.com/en-us/library/ms157905%28v=vs.110%29.aspx方法。用UnhandledExceptionMode.ThrowException
参数将阻止 Winform 将异常路由到Application.ThreadException
事件,因此该对话框永远不会出现。
您还可以更改 app.config 文件以获得相同的结果:
<configuration>
<system.windows.forms jitDebugging="true"/>
</configuration>
我个人更喜欢硬编码路线。
这样我们就清楚了:这只会摆脱对话框,没有解决实际的程序集加载或应用程序冻结问题。 :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)