title: Paralell.ForEach with HttpClient and ContinueWith
body: <p>I have a method that attempts to download data from several URLs in Parallel, and return an <code>IEnumerable</code> of Deserialized types</p>
  
  <p>The method looks like this:</p>
  
  <pre><code>    public IEnumerable&lt;TContent&gt; DownloadContentFromUrls(IEnumerable&lt;string&gt; urls)
      {
          var list = new List&lt;TContent&gt;();
  
          Parallel.ForEach(urls, url =&gt;
          {
              lock (list)
              {
                  _httpClient.GetAsync(url).ContinueWith(request =&gt;
                  {
                      var response = request.Result;
                      //todo ensure success?
  
                      response.Content.ReadAsStringAsync().ContinueWith(text =&gt;
                      {
                          var results = JObject.Parse(text.Result)
                              .ToObject&lt;IEnumerable&lt;TContent&gt;&gt;();
  
                          list.AddRange(results);
                      });
                  });
              }
          });
  
          return list;
      }
  </code></pre>
  
  <p>In my unit test (I stub out _httpClient to return a known set of text) I basically get   </p>
  
  <blockquote>
    <p>Sequence contains no elements</p>
  </blockquote>
  
  <p>This is because the method is returning before the tasks have completed.</p>
  
  <p>If I add .Wait() on the end of my .ContinueWith() calls, it passes, but I'm sure that I'm misusing the API here...</p>