title: How do I code a watchdog timer to restart a Windows service?
body: <p>I'm very interested in the answer to another question regarding watchdog timers for Windows services (see <a href="https://stackoverflow.com/questions/218447/best-way-to-determine-if-a-net-windows-service-has-not-hung/218498#218498">here</a>). That answer stated:</p>
  <blockquote>
  <p>I have also used an internal watchdog system running in another thread. That thread looks at the main thread for activity like log output or a toggling event. If the activity is not seen then the service is considered hung and I shutdown the service.</p>
  <p>In this case you can configure windows to auto-restart a stopped service and that might clear the problem (as long as it's not an internal logic bug).</p>
  <p>Also services I work with have text logs that are written to a log. In addition for services that are about to &quot;sleep for a bit&quot;, I log the time for the next wake up. I use MTAIL to watch a log for output.&quot;</p>
  </blockquote>
  <p>Could anyone give some sample code how to use an internal watchdog running in another thread, since I currently have a task to develop a windows service which will be able to self restart in case it failed, hung up, etc.</p>
  <p>I really appreciate your help.</p>