views:

28

answers:

1

In my Window Service if Service is enable to connect to SQL Server it throws an exception and windows service will not start. To overcome this situation I have set recovery option of Windows Service to First Failure, Second Failure to Restart the Service, Reset fail count after 1 day and Restart Service to 0 minutes.

What I want is when service throws an exception(unhandled) service should go for recovery option which I have configured and should try to restart the service. But this doesnt work.

After configuring service for recovery option if I got to the Task Manager and manually end the process then only this recovery option gets applied.

Can anyone help me on this?

A: 

If we call Environment.Exit( -1 ) it send signal to SCM that service is crashed and Recovery option will get respect.

Hope this will help others like me.

Ravi Khambhati