Reputation: 3884
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!
Upvotes: 0
Views: 2168
Reputation: 13940
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).
Upvotes: 2