private static void DownloadConcurently()
{
string[] urls =
{
"http://www.../",
"http://www...",
"http://..."
};
//System.Threading.Tasks.Parallel...The lambda below is like an anonymous method
Parallel.ForEach(urls, url =>
{
var client = new WebClient();
var html = client.DownloadString(url.ToString());
Console.WriteLine("Download {0} chars from {1} on thread {2}",
html.Length, url, Thread.CurrentThread.ManagedThreadId);
});
}
No comments:
Post a Comment