The Window service cannot restart, even if the Restore option is configured

In my Window service, if the service is turned on to connect to SQL Server, it throws an exception and the Windows service does not start. To overcome this situation, I installed a way to restore the Windows service for the first failure, the second unsuccessful restart of the service, Reset the number of failures after 1 day and restart the service to 0 minutes.

What I want is when the service throws an (unhandled) service exception, should go for the recovery option that I configured, and should try to restart the service. But that does not work.

After configuring the service for recovery, if I got into the Task Manager and manually finished the process, then only this recovery option will be applied.

Can someone help me with this?

+3
source share
1 answer

If we call Environment.Exit( -1 ), it sends an SCM signal that the service is crashing and the restore function will respect.

Hope this helps others like me.

+3
source

Source: https://habr.com/ru/post/1733142/


All Articles