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服务中设置.NET UnhandledException处理?
这不是在Windows服务中设置未处理的异常处理的正确方法吗?
调试。我尝试了解所有的例外情况,但其中一个以某种方式逃避我。我认为这将是一个更易于管理的解决方案。 – 2010-03-16 18:53:58
OnStart或OnStop中发生异常吗?你有关于异常的其他信息吗? – 2010-03-22 13:34:03