title: ThreadAbortException with await
body: <p>I'm facing a weird bug.
  I have something like 100 long running tasks and I want to run 10 of them in the same time.</p>
  
  <p>I found something very similar to my need here : <a href="http://msdn.microsoft.com/en-us/library/hh873173%28v=vs.110%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/hh873173%28v=vs.110%29.aspx</a> in the Throttling section.</p>
  
  <p>Here the C# code after simplification :</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ConsoleApplication1
  {
      public class Program
      {
          static void Main(string[] args)
          {
              Test();
          }
  
          public static async void Test()
          {
              var range = Enumerable.Range(1, 100).ToList();
  
              const int CONCURRENCY_LEVEL = 10;
              int nextIndex = 0;
              var matrixTasks = new List&lt;Task&gt;();
  
              while (nextIndex &lt; CONCURRENCY_LEVEL &amp;&amp; nextIndex &lt; range.Count())
              {
                  int index = nextIndex;
                  matrixTasks.Add(Task.Factory.StartNew(() =&gt; ComputePieceOfMatrix()));
                  nextIndex++;
              }
  
              while (matrixTasks.Count &gt; 0)
              {
                  try
                  {
                      var imageTask = await Task.WhenAny(matrixTasks);
                      matrixTasks.Remove(imageTask);
                  }
                  catch (Exception e)
                  {
                      Console.Write(1);
                      throw;
                  }
  
                  if (nextIndex &lt; range.Count())
                  {
                      int index = nextIndex;
                      matrixTasks.Add(Task.Factory.StartNew(() =&gt; ComputePieceOfMatrix()));
                      nextIndex++;
                  }
              }
  
              await Task.WhenAll(matrixTasks); 
          }
  
          private static void ComputePieceOfMatrix()
          {
              try
              {
                  for (int j = 0; j &lt; 10000000000; j++) ;
              }
              catch (Exception e)
              {
                  Console.Write(2);
                  throw;
              }
          }
      }
  }
  </code></pre>
  
  <p>When running it from a Unit Test a have a ThreadAbortException in ComputePieceOfMatrix.</p>
  
  <p>Do you have any idea ?</p>
  
  <p>Edit :</p>
  
  <p>According to a comment, I tried this : </p>
  
  <pre><code>static void Main(string[] args)
  {
      Run();
  }
  
  private static async void Run()
  {
      await Test();
  }
  
  public static async Task Test()
  {
      var range = Enumerable.Range(1, 100).ToList();
  </code></pre>
  
  <p>But it's exactly the same.</p>