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