Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 Windows服务中的错误处理_C# 4.0_Windows Services_Error Handling - Fatal编程技术网

C# 4.0 Windows服务中的错误处理

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.

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

protected override void OnStart(string[] args)
{

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

我在这里遗漏了什么吗?

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