title: Await Parallel.ForEach
body: <p>I am stuck in a situation where I have to download multiple files from a list of urls. I found <code>Parallel.ForEach</code> as a solution and it really works faster than a simple foreach. But this solution is <strong>not waiting</strong> till all downloads are done.</p>
  
  <pre><code>List&lt;string&gt; list = new List&lt;string&gt;() {"url1","url2","url3",... };
  
  public async void downloadSimpleFile(string fileUrl) {
      //download file logic
  }
  
  await Task.Factory.StartNew(() =&gt; Parallel.ForEach(list,
      new ParallelOptions { MaxDegreeOfParallelism = 10 }, downloadSimpleFile));
  </code></pre>
  
  <p>I was also tying:</p>
  
  <pre><code>public async Task&lt;bool&gt; downloadSimpleFile(string fileUrl) {
      //download file logic
      return true;
  }
  </code></pre>
  
  <p>Now how can I use <code>downloadSimpleFile</code> in <code>Parallel.ForEach</code>, because up mentioned code is not working anymore?</p>
  
  <p>I was reading some posts about async-await in <code>Parallel</code> like <a href="https://stackoverflow.com/questions/23137393/parallel-foreach-and-async-await">this</a> or <a href="https://stackoverflow.com/questions/11564506/nesting-await-in-parallell-foreach">this</a> but I'm not getting the idea. Any ideas are apreciated.</p>