Tutorial :Restart Windows Service when faulted



Question:

We have an windows service written in .net, that is hosting WCF service. My question is, Is it possible to monitor and restart service on any fault, in other world I want my service to be restarted automaticaly on any fault.
Thanks a lot


Solution:1

Start / Control Panel / Services / right-click your service / Properties / First failure : restart the service / Second failure : restart the service / Subsequent failure : restart the service.

Should do it.


Solution:2

Go into the service manager in the OS, right-click your service and choose properties. There you'll find a recovery tab which lets you define behavior on crashes.


Solution:3

Within single windows service there can be multiple WCF services. You can handle Faulted event of the ServiceHost class for individual WCF service and re-initialize it.


Solution:4

I think you should think about the design of your service. It should be a host to the wcf process. You could make 3 threads:

  • Main thread (only stops on v FATAL error)

  • ExceptionHandler thread (handles "expected" exceptions and does logging and takes care of the WCFHost thread dying)

  • WCFHost thread (Hosts the WCF Service and can die as often as it likes the ExceptionHandler can take care of this now.)


Solution:5

You could write another service like a watcher service that will monitor this core service & will re-start it when stopped. However, nothing can be done if the watcher service is stopped.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »