protected override void OnStart(string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Thread.Sleep(10000);
throw new Exception();
}
void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
}
我在我的 Windows 服务中将调试器附加到上述代码,在 CurrentDomain_UnhandledException 中设置了一个断点,但它从未被命中。弹出异常说它未处理,然后服务停止。我什至尝试将一些代码放入事件处理程序中,以防它被优化掉。
这不是在 Windows 服务中设置未处理异常处理的正确方法吗?