Skip to content

Instantly share code, notes, and snippets.

@shawnweisfeld
Last active August 29, 2015 14:15
Show Gist options
  • Save shawnweisfeld/7cee9b12b306b66cdd4e to your computer and use it in GitHub Desktop.
Save shawnweisfeld/7cee9b12b306b66cdd4e to your computer and use it in GitHub Desktop.
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var downloads = new List<Task>();
while (downloads.Count < 10)
{
downloads.Add(DownloadPageAsync("http://bing.com"));
}
Console.WriteLine("Requests queued!");
Task.WaitAll(downloads.ToArray());
Console.WriteLine("Done!");
Console.ReadKey();
}
private async static Task DownloadPageAsync(string url)
{
using (WebClient client = new WebClient())
{
var page = await client.DownloadStringTaskAsync(url);
Console.WriteLine(page.Substring(0, 25));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment