2011-05-06 72 views
0

如何在Windows服務中編寫通用錯誤處理程序?我在OnStart方法中嘗試了以下代碼,但它沒有捕獲異常。Windows服務中的錯誤處理

protected override void OnStart(string[] args) 
{ 

       AppDomain.CurrentDomain.UnhandledException += new 
UnhandledExceptionEventHandler(UnhandledExceptionTrapper); 
       this.Start(); 
} 

有什麼我在這裏失蹤?

回答

0

您可能會在後臺線程中收到異常。將所有事件處理程序中的所有代碼包裝在try/catch塊中。