-1

The reason I wanted to restart the services is because sometimes one of those services stops to do the task it was made for. The service status is still running in the service control manager. When the service is restarted then everything works fine. I am not sure why this happening. I have try and catch blocks everywhere in the code. Database connections are Created / Opened / Closed / Destroyed etc.

Any ideas?

vela
  • 147
  • 10
vikas
  • 1
  • 1
  • To answer you question *"Or should I chose some other approach?"* **YES**. You should fix the underlying problem instead. How would you even know (reliably) **when** to restart? **Who** would restart it? – Manfred Radlwimmer Jan 27 '17 at 07:48

1 Answers1

1

Here are your options:

  1. Fix the underlying problems if you can.

  2. If you can't fix the underlying problems (e.g. you have some code that is extremely complicated or opaque), move the troublesome code to a separate process. Your service can spawn this process and occasionally kill it. Giving it its own process allows you to abort it and reclaim the resources even if it freezes up. Make the service a simple wrapper.

  3. If you don't want to split up the code, and the service's requirements are a good fit for this, perhaps you could make it a simple executable, and run it with Windows Task Scheduler instead of as a service.

  4. If you can't modify the service itself, you can restart the service programmatically.

Community
  • 1
  • 1
John Wu
  • 50,556
  • 8
  • 44
  • 80