Created
November 13, 2017 13:19
-
-
Save yevhen/fa81acdfa42511ee60b1c678b2980889 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
readonly HttpClient http = new HttpClient(); | |
async Task<DownloadResult[]> DownloadUrlsAsync(string path) => | |
await Task.WhenAll(File.ReadLines(path).Select(DownloadAsync)); | |
async Task<DownloadResult> DownloadAsync(string url) | |
{ | |
var time = Stopwatch.StartNew(); | |
try | |
{ | |
return new DownloadResult | |
{ | |
Url = url, | |
Time = time.ElapsedMilliseconds, | |
Success = true, | |
SizeInBytes = (await http.GetByteArrayAsync(url)).Length | |
}; | |
} | |
catch (Exception x) | |
{ | |
Console.WriteLine("error downloading {0}: {1}", url, x); | |
return new DownloadResult | |
{ | |
Url = url, | |
Time = time.ElapsedMilliseconds, | |
}; | |
} | |
} | |
class DownloadResult | |
{ | |
public string Url; | |
public long Time; | |
public bool Success; | |
public int SizeInBytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment