简体   繁体   English

Windows服务中未处理的异常

[英]Unhandled Exception in Windows Service

I am using system.timer in a windows service application (c#) and have added: 我在Windows服务应用程序(c#)中使用system.timer并添加了:

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += 
       new UnhandledExceptionEventHandler(MyExceptionHandler);

To handle my exceptions, does this work in a Windows Service as it does not seem to work? 要处理我的异常,这是否在Windows服务中工作,因为它似乎不起作用? Does anyone have any alternative ideas? 有没有人有任何其他想法?

This mechanism will work to capture Unhandled Exceptions in any environment including Windows Services. 此机制将用于捕获包括Windows服务在内的任何环境中的未处理异常。 However there are some limitations on what kind of exceptions can be handled in this way. 但是,以这种方式处理什么样的异常存在一些限制。 For instance, a StackOverFlowException may be unhandled but do to it's nature you won't ever see it go through an UnhandledException handler. 例如,StackOverFlowException可能未处理,但它的性质是你永远不会看到它通过UnhandledException处理程序。

Why do you think this is not working? 为什么你认为这不起作用? Have you tried attaching to the process with a debugger , enabling first chance exceptions and see what is going on? 您是否尝试使用调试器附加到该过程,启用第一次机会异常并查看发生了什么?

Why do you have an unhandled exception in a service? 为什么服务中有未处理的异常? What is the exception? 什么例外? Some exceptions have "special behavior" ( and another link here for .NET 4 changes to corrupted state exceptions ). 一些例外具有“特殊行为”此处的另一个链接是.NET 4更改为损坏的状态异常 )。

Also, what are you trying to do in the handler? 另外,你想在处理程序中做什么? Maybe the actions you're trying to do in the handler are what's limited when running as a service. 也许您在处理程序中尝试执行的操作在作为服务运行时受到限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM