2011-05-06 91 views
0

如何在Windows服务中编写通用错误处理程序?我在OnStart方法中尝试了以下代码,但它没有捕获异常。Windows服务中的错误处理

protected override void OnStart(string[] args) 
{ 

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

有什么我在这里失踪?

回答

0

您可能会在后台线程中收到异常。将所有事件处理程序中的所有代码包装在try/catch块中。