我在想,最好的方法是"如果其他方法都不能抓住它".
我是说,你在应用程序中处理了尽可能多的异常,
应用程序域不存在.CurrentDomain.未处理的异常事件是否捕获了所有内容?
旁注:Windows Vista公开了允许任何应用程序使用的本机API函数
我在想,最好的方法是"如果其他方法都不能抓住它".
我是说,你在应用程序中处理了尽可能多的异常,
应用程序域不存在.CurrentDomain.未处理的异常事件是否捕获了所有内容?
旁注:Windows Vista公开了允许任何应用程序使用的本机API函数
我刚刚玩过AppDomain未处理的异常行为,
是的,在处理事件处理程序后,应用程序将被终止,并显示"程序停止工作"对话框.
:)
查看:
class Program
{
void Run()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Console.WriteLine("Press enter to exit.");
do
{
(new Thread(delegate()
{
throw new ArgumentException("ha-ha");
})).Start();
} while (Console.ReadLine().Trim().ToLowerInvariant() == "x");
Console.WriteLine("last good-bye");
}
int r = 0;
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Interlocked.Increment(ref r);
Console.WriteLine("handled. {0}", r);
Console.WriteLine("Terminating " + e.IsTerminating.ToString());
Thread.CurrentThread.IsBackground = true;
Thread.CurrentThread.Name = "Dead thread";
while (true)
Thread.Sleep(TimeSpan.FromHours(1));
//Process.GetCurrentProcess().Kill();
}
static void Main(string[] args)
{
Console.WriteLine("...");
(new Program()).Run();
}
}
P.S..处理未经处理的申请.更高级别的ThreadException(WinForms)或DispatcherUnhandleException(WPF).