unhandled exceptions in a windows service

旧城冷巷雨未停 提交于 2019-12-05 19:59:18

I included exception handling in it but I would like to set up a global handler to catch unhandled exceptions in the windows service

You could use AppDomain.UnhandledException. In your case however, your entire call to your service can be wrapped in a try/catch block. Since you haven't provided details for what you plan to do with this unhandled exception, your correct path I think in this case is to let the service crash.

try
{
   MainCallToYourService();
}
catch (Exception)
{
   //it's probably too late to do anything useful here, try to log and die
}

Keep in mind though that the problem in doing this is that in a lot of cases, your application's state is corrupt by the time this event is raised. Your best bet is to try and log it and get out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!