title: Error while stopping windows service
body: <p>I am working on Windows Service. It works fine. When i am trying to stop the service from <code>services.msc</code>, it throws the following error:</p>
  
  <blockquote>
    <p>Windows could not stop the xxx service on Local Computer.
    The service did not return an error.  This could be an internal Windows error or an internal service error.
    If the problem persists, contact your system administrator.</p>
  </blockquote>
  
  <p>If I try to stop it again, it takes lots of time and then throws the error as below:</p>
  
  <blockquote>
    <p>Windows could not stop the xxx service on Local Computer.
    Error 1061: The service cannot accept control messages at this time.</p>
  </blockquote>
  
  <p>At this point, the service has stopped. But if I try to reinstall the service, it throws another error:</p>
  
  <blockquote>
    <p>Windows could not stop the xxx service on Local Computer.<br>
    Error 1001: The specified service is marked for deletion.</p>
  </blockquote>
  
  <p>After closing <code>services.msc</code>, it lets me reinstall the service and again things start working fine.</p>
  
  <p>In <code>OnStop()</code>, I am doing some lengthy operations and it takes time to complete.</p>
  
  <p>Any idea how I can make the whole thing go smoothly?</p>
  
  <p>--Edit--</p>
  
  <p>This is what my <code>OnStop</code> method looks like:</p>
  
  <pre><code>protected override void OnStop()
  {
      base.OnStop();
      //Some lengthy operation      
  }
  </code></pre>