简体   繁体   中英

Reasons for windows service to stop

I have designed a windows service in C#, which runs continiously and spawns three threads. The first thread runs every 15 sec. The second thread runs every min. And the thirs runs only once.

My problem is that this windows service somehow just stops after few days.There is nothing logged in the eventlog on the day of stopping.And it didn't write anything in the logging file.

I want to know what are the various reasons for a windows service to stop abruptly. And this service is not on my DEV box, it is on QA server.

hope it make sense!

You probably have an unhandled exception on one of your threads- since .NET 2.0, unhandled exceptions will take down the process abruptly like this. Make sure the top of stack for anything you run on a thread has a catch block to handle errors (log, swallow, marshal to another thread, whatever). You can temporarily prevent this behavior (eg, revert to pre-.NET 2.0 behavior) by adding the following to your service's .exe.config file:

<configuration>
  <runtime>
    <legacyUnhandledExceptionPolicy enabled="1" />
  </runtime>
</configuration>

but don't rely on it- it may be removed in a future .NET release (haven't checked 4.0- it may already be gone).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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