How to announce Windows Service Manager, that service fails (Recovery Options)
-
Hello, the Windows Service Manager provides some recovery options. In the properties of a service, you can select the computer's response if the service fails. For example, First failure >> Restart the Service. How can I announce the Windows Service Manager, that my own service fails, so that the recovery options start the work? Has anyone a code example? Thanks in advance Best regards, Jan Lehmann [Germany]
-
Hello, the Windows Service Manager provides some recovery options. In the properties of a service, you can select the computer's response if the service fails. For example, First failure >> Restart the Service. How can I announce the Windows Service Manager, that my own service fails, so that the recovery options start the work? Has anyone a code example? Thanks in advance Best regards, Jan Lehmann [Germany]
If your service throws an unhandled exception, the SCM will handle it. If your service terminates abruptly (such as it's process being killed), the SCM will handle it.
// c# Process.GetCurrentProcess().Kill();
A really good way to get Windows to know your app failed most heinously is to use Interop and RaiseException and pass
EXCEPTION_NONCONTINUABLE
for thedwExceptionFlags
parameter.Ian Mariano - Bliki | Blog
"We are all wave equations in the information matrix of the universe" - me -
Hello, the Windows Service Manager provides some recovery options. In the properties of a service, you can select the computer's response if the service fails. For example, First failure >> Restart the Service. How can I announce the Windows Service Manager, that my own service fails, so that the recovery options start the work? Has anyone a code example? Thanks in advance Best regards, Jan Lehmann [Germany]
It's also probably a very good idea to log the service failure in the Windows Event Log, or publish it to WMI.
// c# panic(), expects message as a string parameter EventLog log = new EventLog(...); log.Write(message, EventLogEntryType.Error); Process.GetCurrentProcess().Kill();
It should be noted that forcibly terminating an application without at least attempting a graceful shutdown / release of resources is a bad idea. If possible, cleanup what you can before
Kill
ing the process.Ian Mariano - Bliki | Blog
"We are all wave equations in the information matrix of the universe" - me