title: How to return Task output from an anonymous method?
body: <p>I've this method:</p>
  
  <pre><code>public async Task Method1Async()
  {
      var foo = 1;
      var bar = 100;
  
      List&lt;Task&gt; tasks = new List&lt;Task&gt;();
      for (int i = 0; i &lt; 10; i++)
      {
         // add below code here
      }       
      await Task.WhenAll(tasks);
  }
  </code></pre>
  
  <p>and I want to add this code to the <code>tasks</code> above and wait for all to finish:</p>
  
  <pre><code>// do something
  await Method2Async(foo, bar); 
  // do something else
  </code></pre>
  
  <p>How can I do that? Thanks..</p>
  
  <hr>
  
  <p>I tried this, but <code>Task.WhenAll</code> waits for ever:</p>
  
  <pre><code>public async Task Method1Async()
  {
      var foo = 1;
      var bar = 100;
  
      List&lt;Task&gt; tasks = new List&lt;Task&gt;();
      for (int i = 0; i &lt; 10; i++)
      {
          tasks.Add(new Task(async () =&gt;
          {
              // do something
              await Method2Async(foo, bar); 
              // do something else
          }
      }       
      await Task.WhenAll(tasks);
  }
  </code></pre>