title: Why doesn't this exception get thrown?
body: <p>I use a set of tasks at times, and in order to make sure they are all awaited I use this approach:</p>
  
  <pre><code>public async Task ReleaseAsync(params Task[] TaskArray)
  {
    var tasks = new HashSet&lt;Task&gt;(TaskArray);
    while (tasks.Any()) tasks.Remove(await Task.WhenAny(tasks));
  }
  </code></pre>
  
  <p>and then call it like this:</p>
  
  <pre><code>await ReleaseAsync(task1, task2, task3);
  //or
  await ReleaseAsync(tasks.ToArray());
  </code></pre>
  
  <p>However, recently I have been noticing some strange behavior and set to see if there was a problem with the ReleaseAsync method. I managed to narrow it down to this simple demo, it runs in linqpad if you include <code>System.Threading.Tasks</code>. It will also work slightly modified in a console app or in an asp.net mvc controller.</p>
  
  <pre><code>async void Main()
  {
   Task[] TaskArray = new Task[]{run()};
   var tasks = new HashSet&lt;Task&gt;(TaskArray);
   while (tasks.Any&lt;Task&gt;()) tasks.Remove(await Task.WhenAny(tasks));
  }
  
  public async Task&lt;int&gt; run()
  {
   return await Task.Run(() =&gt; {
    Console.WriteLine("started");
    throw new Exception("broke");
    Console.WriteLine("complete");
    return 5;
   });
  }
  </code></pre>
  
  <p>What I don't understand is why the Exception never shows up anywhere. I would have figured that if the Tasks with the exception were awaited, it would throw. I was able to confirm this by replacing the while loop with a simple for each like this:</p>
  
  <pre><code>foreach( var task in TaskArray )
  {
    await task;//this will throw the exception properly
  }
  </code></pre>
  
  <p>My question is, why doesn't the shown example throw the exception properly (it never shows up anywhere).</p>