C# 4.0 Windows服务中的错误处理
如何在windows服务中编写通用错误处理程序?我在OnStart方法中尝试了以下代码,但它无法捕获异常C# 4.0 Windows服务中的错误处理,c#-4.0,windows-services,error-handling,C# 4.0,Windows Services,Error Handling,如何在windows服务中编写通用错误处理程序?我在OnStart方法中尝试了以下代码,但它无法捕获异常 protected override void OnStart(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionTrapper); this.
protected override void OnStart(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(UnhandledExceptionTrapper);
this.Start();
}
我在这里遗漏了什么吗?您可能在后台线程中遇到异常。将所有事件处理程序中的所有代码包装到try/catch块中