title: ContinueWhenAll doesn't wait for all task to complete
body: <p>I have found a piece of code on the web and have modified it a bit to see how it works, but now I have a problem with <code>ContinueWhenAll</code> as it doesn't wait for all tasks to be finished:</p>
  
  <pre><code>List&lt;Task&gt; tasks = new List&lt;Task&gt;();
  for (int i = 0; i &lt; 20; i++)
  {
      int j = i;
      var compute = Task.Factory.StartNew(() =&gt; results.Add(DoSomething(j)));
      tasks.Add(compute);
  }
  </code></pre>
  
  <p>I'm using this code to add all task to list. <code>DoSomething</code> function computes some results and adds them to <code>BlockingCollection</code>. I have another display function which writes all added results from <code>BlockingCollection</code> to the console.</p>
  
  <p>I have used this code to wait for all tasks to complete, but it looks like it doesn't wait for them as the program displays the standard <code>"Press any key to continue"</code> message just a few milliseconds after it was started. (It should take ~20 sec for program to complete)</p>
  
  <pre><code>Task.Factory.ContinueWhenAll(tasks.ToArray(), result =&gt; results.CompleteAdding());
  </code></pre>
  
  <p>However if I add <code>Task.WaitAll(consume)</code> to end of the program, program works fine:</p>
  
  <pre><code>var consume = Task.Factory.StartNew(() =&gt; display(results));
  //results = BlockingCollection that I mentioned 
  </code></pre>
  
  <p>As far as I understand, the program will not have enough time to display all result from <code>BlockingCollection</code> but still it has more than enough time to display some while waiting for all tasks to complete.</p>
  
  <p>Could someone explain me why Task.Factory.ContinueWhenAll doesn't wait for all results to be computed and program comes to an end just like there is no that line of code in program (after few milliseconds)?</p>