title: await Task.WhenAll() vs Task.WhenAll().Wait()
body: <p>I have a method that produces an array of tasks (<a href="https://stackoverflow.com/questions/22961890/c-sharp-how-to-wait-until-all-tasks-are-finished-before-running-code">See my previous post about threading</a>) and at the end of this method I have the following options:</p>
  
  <pre><code>await Task.WhenAll(tasks); // done in a method marked with async
  Task.WhenAll(tasks).Wait(); // done in any type of method
  Task.WaitAll(tasks);
  </code></pre>
  
  <p>Basically I am wanting to know what the difference between the two <code>whenall</code>s are as the first one doesn't seem to wait until tasks are completed where as the second one does, but I'm not wanting to use the second one if it's not asynchronus.</p>
  
  <p>I have included the third option as I understand that this will lock the current thread until all the tasks have completed processing (seemingly synchronously instead of asynchronus) - please correct me if I am wrong about this one</p>
  
  <p>Example function with await:</p>
  
  <pre><code>public async void RunSearchAsync()
  {
      _tasks = new List&lt;Task&gt;();
      Task&lt;List&lt;SearchResult&gt;&gt; products = SearchProductsAsync(CoreCache.AllProducts);
      Task&lt;List&lt;SearchResult&gt;&gt; brochures = SearchProductsAsync(CoreCache.AllBrochures);
  
      _tasks.Add(products);
      _tasks.Add(brochures);
  
      await Task.WhenAll(_tasks.ToArray());
      //code here hit before all _tasks completed but if I take off the async and change the above line to:
  
      // Task.WhenAll(_tasks.ToArray()).Wait();
      // code here hit after _tasks are completed
   }
  </code></pre>