title: C# asynchronous tasks with Task.WhenAll() not working
body: <p>I am trying to execute multiple tasks asynchronously. And then wait for all before proceeding.
  But somehow my all tasks are not completing. Review my sample code.</p>
  
  <pre><code>//List from database
  List&lt;Promotion&gt; promotions = _dbContext.promotions.ToList();
  
  var promotionTasks = new List&lt;Task&gt;();
  List&lt;Promotion&gt; outputPromotions = new List&lt;Promotion&gt;();
  foreach (var promotion in promotions)
  {
      var task = Task.Run(() =&gt;
      {
          var promotionStatus = GetPromotionStatus(promotion).Result;
          var newPromotion = new Promotion
          {
              Id = promotion.Id,
              Name = promotion.Name,
              Code = promotion.Code,
              StatusId = promotionStatus
          };
  
          outputPromotions.Add(newPromotion);
      });
      promotionTasks.Add(task);
  }
  
  //await Task.WhenAll(promotionTasks);
  Task.WaitAll(promotionTasks.ToArray());
  
  //Output list
  return outputPromotions;
  </code></pre>
  
  <p>For e.g
  I am getting 50 values in <code>promotions</code> (which is original list and its from database). and then after the completion of all tasks i am not getting the all 50 values in outputPromotions consistantly.
  <code>outputPromotions</code> it gives me count like 49,48,50,46 not all 50 every time.
  I have tried await <code>Task.WhenAll(promotionTasks);</code> and <code>Task.WaitAll(promotionTasks.ToArray());</code> both but same result.</p>
  
  <p>Can anyone suggest what I am doing wrong here?</p>