private void ReportWebsiteInfo(WebsiteDataModel data) { txt_Logging.Text += $"{data.WebsiteUrl} downloaded: " + $"{data.WebsiteData.Length} characters long " + $" execution time: {data.DownloadTime} ms" + $"{Environment.NewLine}"; }
private void RunDownloadSync() { IList <String> websites = PrepData(); foreach (var website in websites) { WebsiteDataModel results = DownloadWebsite(website); ReportWebsiteInfo(results); } }
private async Task RunDownloadAsync() { IList <String> websites = PrepData(); foreach (var website in websites) { WebsiteDataModel results = await Task.Run(() => DownloadWebsite(website)); ReportWebsiteInfo(results); } }
private WebsiteDataModel DownloadWebsite(string website) { WebsiteDataModel model = new WebsiteDataModel(); WebClient client = new WebClient(); model.WebsiteUrl = website; var clock = Stopwatch.StartNew(); model.WebsiteData = client.DownloadString(website); clock.Stop(); model.DownloadTime = clock.ElapsedMilliseconds; return(model); }