title: Wait for all threads to release semaphore?
body: <p>How do I close down and wait for a semaphore to be fully released?</p>
  
  <pre><code>private SemaphoreSlim _processSemaphore = new SemaphoreSlim(10);
  
  public async Task&lt;Modification&gt; Process(IList&lt;Command&gt; commands)
  {
    Assert.IsFalse(_shuttingDown, "Server is in shutdown phase");
    await _processSemaphore.WaitAsync();
  
    try
    {
      // threads that have reached this far must be allowed to complete
      return _database.Process(commands);
    }
    finally
    {
      _processSemaphore.Release();
    }
  }
  
  public async Task StopAsync()
  {
    _shuttingDown = true;
  
    // how wait for threads to complete without cancelling?
    await ?
  }
  </code></pre>