title: Task.Yield cause more deadlock with than without
body: <p>in asp net core, I'm encountering deadlocks on shutdown, due to apparently an issue I have in some tasks I'm running in the background.
  Here's what I'm doing in a background service :</p>
  <pre><code>protected override async Task ExecuteAsync(CancellationToken ct)
      {
         
          async Task ConsumeFromQueue(int i)
          {
              while (!ct.IsCancellationRequested)
              {
                  // purely blocking code here (at least, assume it is always blocking in some scenario here where I don't have any work to do)
                  await Task.Yield();
              }
          }
  
          var workerTasksArray = Enumerable.Range(0, 10).Select(i =&gt; Task.Run(() =&gt; ConsumeFromQueue(i))).ToArray();
          await Task.WhenAll(workerTasksArray);
  }
  </code></pre>
  <p>Running this seems to prevent any other async things from happening, namely application shutdown.
  If I switch Task.Yield(); for a Task.Delay(1);, everything works.
  Weirdly enough, if I completely remove all await and make ConsumeFromQueue() purely synchronous, every works again.</p>
  <p>Can someone explain what I'm doing wrong in my initial implementation?
  I was assuming that Task.Yield would ensure that some other async tasks from other parts of the program can always &quot;sneak in&quot; and get executed. Or am I blocking all threadpool threads because Task.Yield doesn't switch threads ? (from my understanding)</p>