title: WCF ServiceHost Close() itself
body: <p>I have an application which offers a "Stop()" OperationContract.
  When it is called the application should close() the ServiceHost.</p>
  
  <pre><code>public void Stop()
  {
      try
      {
          _serviceHost.Close(TimeSpan.FromSeconds(10));
      }
      catch (CommunicationException comEx)
      {
          Console.WriteLine(comEx.ToString());
          _serviceHost.Abort();
      }
  }
  </code></pre>
  
  <p>Of course this is a problem because the incoming request is still active when trying to close the ServiceHost. How do I circumvent that issue? Separate thread on a short delay?</p>
  
  <pre><code>public void Stop()
  {
      Task.Factory.StartNew(WaitAndKill);
  }
  
  
  private void WaitAndKill()
  {
      Thread.Sleep(500);
  
      _managementServiceHost.Close();
  }
  </code></pre>