title: Where should I add my own code in the service template?
body: <p>Microsoft provides a <a href="https://docs.microsoft.com/fr-fr/windows/desktop/Services/the-complete-service-sample" rel="nofollow noreferrer">complete service sample</a> to start with writing Windows services. However, I do not understand the following part from <a href="https://docs.microsoft.com/fr-fr/windows/desktop/Services/svc-cpp" rel="nofollow noreferrer">this file</a> :</p>
  
  <pre><code>ReportSvcStatus( SERVICE_RUNNING, NO_ERROR, 0 );
  
  // TO_DO: Perform work until service stops.
  
  while(1)
  {
      // Check whether to stop the service.
  
      WaitForSingleObject(ghSvcStopEvent, INFINITE);
  
      ReportSvcStatus( SERVICE_STOPPED, NO_ERROR, 0 );
      return;
  }
  </code></pre>
  
  <p>I don't understand the point of the infinite loop containing a return statement. Doesn't it defeat the purpose ?</p>
  
  <p>It seems to encourage to write the service content before the while loop but then, if we do not reach the following line :</p>
  
  <pre><code>WaitForSingleObject(ghSvcStopEvent, INFINITE);
  </code></pre>
  
  <p>... The service will not able to stop when the proper event is triggered, would it ?</p>
  
  <p>Is this template flawed ? How can I make my service wait for an external trigger without making it impervious to stop calls ?</p>