title: What is the best way to keep a ATL service running
body: <p>I have created a ATL service and while testing I simply kept it running by leaving a while loop that ran forever (see code below)</p>
  
  <pre><code>HRESULT Run(_In_ int nShowCmd = SW_HIDE)
  {
      m_running = true;
      HANDLE thread = (HANDLE)_beginthreadex(NULL, 0, &amp;MyFunctionToRunInTheService, 0, 0, 0);
      while(m_running);
      return CAtlServiceModuleT::Run(nShowCmd);
  }
  </code></pre>
  
  <p>Im now ready to actually run it as a real service but am not sure how I go about doing this? I have looked all over the next and dont seem to be able to find one example of a ATL service. </p>
  
  <p>If I remove the thread code and call the method direct the service is constantly in a start status. If i remove the loop the service simply starts and stops straight away. Any sugestions?</p>