title: How to ensure Windows service process is always running?
body: <p>I have a Windows service that is calling a stored proc over and over (in an infinite loop).</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>while(1)
  {
     callStoredProc();
     doSomethingWithResults();
  }
  </code></pre>
  
  <p>However, how there might be cases where the loop gets stuck with no response, but the service is still technically running.</p>
  
  <p>I imagine there are tools to monitor the health of a service, to let operations teams know to restart it.</p>
  
  <p>But for my scenario this won't help since the service will still be technically running, but it's stuck and can't continue.</p>
  
  <p>What's the best way to ensure this process restarts if this scenario happens?</p>
  
  <p>Would the solution be to use a task scheduler that checks for the heartbeat of this process, and restarts the service if it there's no heartbeat for a period of time? To have another separate thread that monitors the progress of the first process?</p>