title: Await and task concurrency
body: <p>I am trying to create a TaskScheduler that limits the number of threads that can be run at the same time. I'm using <a href="https://msdn.microsoft.com/en-us/library/ee789351(v=vs.110).aspx" rel="nofollow">this example</a>.  The problem is that I'm seeing some behavior I don't understand.</p>
  
  <p>If I create my class like the example:</p>
  
  <pre><code>LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(5);
  TaskFactory factory = new TaskFactory(lcts);
  </code></pre>
  
  <p>And then run it like this:</p>
  
  <pre><code>foreach (int i = 0; i &lt; 10; ++i) 
  {
      factory.StartNew(() =&gt; DoWork());
  }
  </code></pre>
  
  <p>And do work looks like this:</p>
  
  <pre><code>private async Task DoWork()
  {
      // Do some stuff here like
      StaticIntValueWorkOne++;
  
      // And then more stuff that is async here
      int someValue = await DoAdditionalWorkAsync();
      Thread.Sleep(10000);
      StaticIntValueWorkTwo++;
  }
  </code></pre>
  
  <p>What I see is that <code>StaticIntValueWorkOne</code> is incremented immediately 10 times, while <code>StaticIntValueWorkTwo</code> is only incremented once.  Then after 10s I see <code>StaticIntValueWorkTwo</code> incremented, and then every 10s after that.  What I'm not getting is what the await on <code>DoAdditionalWorkAsync()</code> is doing with the concurrency.  I was thinking that I would see <code>StaticIntValueWorkOne</code> incremented once, and then <code>StaticIntValueWorkTwo</code> would increment once.  What am I missing?  Do I just need an <code>await</code> on the <code>factor.StartNew()</code>?</p>