Last active
August 29, 2015 14:15
-
-
Save shawnweisfeld/7cee9b12b306b66cdd4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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