Download webpages parallelly with c#

We can use the C# task parallel library with the ConcurrentDictionary to retrieve a list of known addresses in parallel.

var urls = new List<string> 
{ 
  @"http://www.w3mentor.com", 
  @"http://www.storewala.com", 
  @"http://reviewable.in"
};
var results = new ConcurrentDictionary<string,string>();
var client = new System.Net.WebClient();
 
Parallel.ForEach(urls, url => results[url] = 
     client.DownloadString(url));

Enjoyed this post? Share it!