有时候代码中忘记写try catch的时候系统会崩掉,这时在最外边使用
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = e.ExceptionObject as Exception;
}
catch { }
}
此方法可以再多个环境中使用,包括windows服务以及异步操作