title: Task.StartNew() vs Parallel.ForEach : Multiple Web Requests Scenario
body: <p>I have read through all the related questions in SO, but a little confused on the best approach for my scenario where multiple web service calls are fired.</p>
  <p>I have an aggregator service that takes an input, parses and translates it into multiple web requests, makes the web request calls (unrelated, so could be fired in parallel) and consolidates the response which is sent back to the caller. The following code is used right now -</p>
  <pre><code>list.ForEach((object obj) =&gt;
  {
       tasks.Add(Task.Factory.StartNew((object state) =&gt; 
       {
             this.ProcessRequest(obj);
       }, obj, CancellationToken.None,
       TaskCreationOptions.AttachedToParent, TaskScheduler.Default));
  });
  await Task.WhenAll(tasks);
  </code></pre>
  <p>the <code>await Task.WhenAll(tasks)</code> comes from Scott Hanselman's <a href="http://www.hanselman.com/blog/BackToParallelBasicsDontBlockYourThreadsMakeAsyncIOWorkForYou.aspx" rel="nofollow noreferrer">post</a> where it is said that</p>
  <blockquote>
  <p>&quot;A better solution from a scalability perspective, says Stephen, is to
  take advantage of asynchronous I/O.  When you're calling out across
  the network, there's no reason (other than convenience) to blocks
  threads while waiting for the response to come back&quot;</p>
  </blockquote>
  <p>The existing code appears to consume too many threads and the Processor Time shoots up to 100% on production load and that gets me thinking.</p>
  <p>The other alternate is to use Parallel.ForEach which uses a partitioner but and also &quot;blocks&quot; the call, which is fine for my scenario.</p>
  <p>Considering this is all &quot;Async IO&quot; work and not &quot;CPU bound&quot; work, and the web requests are not long running (return in max 3 seconds), I tend to believe the existing code is good enough. But would this provide better throughput than Parallel.ForEach? Parallel.ForEach probably uses &quot;minimal&quot; number of Tasks because of the partitioning and therefore optimal use of threads(?). I did test Parallel.ForEach with some local tests and it doesn't appear to be any better.</p>
  <p>The goal is to reduce the CPU time and increase throughput and therefore better scalability. Is there a better approach for handling web requests in parallel?</p>
  <p>Appreciate any inputs, thanks.</p>
  <p><strong>EDIT:</strong>
  ProcessRequest method shown in the code sample indeed uses HttpClient and its async methods to fire requests (PostAsync, GetAsync, PutAsync).</p>