Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created March 4, 2012 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmanning/1974032 to your computer and use it in GitHub Desktop.
Save jamesmanning/1974032 to your computer and use it in GitHub Desktop.
download urls, async, takes collection
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
namespace ItsBigItsHeavyItsWood
{
class Program
{
static void Main()
{
var urlsToDownload = new[]
{
"http://www.google.com/",
"http://www.microsoft.com/",
"http://www.apple.com/",
};
DownloadUrls(urlsToDownload);
Console.ReadLine();
}
private static async void DownloadUrls(IEnumerable<string> urlsToDownload)
{
foreach (var url in urlsToDownload)
{
var client = new HttpClient();
Console.WriteLine("Starting to download url {0}", url);
var contents = await client.GetByteArrayAsync(url);
Console.WriteLine("Downloaded {0} bytes", contents.Length);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment