title: Waiting for all tasks to finish using Task Parallel Library in .NET 4.0
body: <p>Is there a shorter way to wait for multiple threads to finish?  Maybe using ContinueWhenAll... but I don't want to run the rest of my code async.</p>
  
  <pre><code>List&lt;object&gt; objList = // something
  
  List&lt;Task&gt; taskHandles = new List&lt;Task&gt;();
  for(int i = 0; i &lt; objList.Count; i++) {
  
      taskHandles.Add(Task.Factory.StartNew(() =&gt; { Process(objList[i]); }));
  
  }
  
  foreach(Task t in taskHandles) { t.Wait(); }
  
  DoSomeSync1();
  ..
  DoSomeSync2();
  ..
  DoSomeSync3();
  ..
  
  // I could have used ContinueWhenAll(waitHandles, (antecedent) =&gt; { DoSomeSync...; });
  // but I'd rather not have to do that.
  // It would be nice if I could have just done:
  
  Parallel.ForEach(objList, (obj) =&gt; { Process(obj); }).WaitAll();
  
  // or something like that.
  </code></pre>