private async Task <WebsiteDataModel> DownloadWebsiteAsync(string websiteURL) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteUrl = websiteURL; output.WebsiteData = await client.DownloadStringTaskAsync(websiteURL); return(output); }
private WebsiteDataModel DownloadWebsite(string websiteURL) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteUrl = websiteURL; output.WebsiteData = client.DownloadString(websiteURL); return(output); }
private void RunDownloadSync() { List <string> websites = PrepData(); foreach (string site in websites) { WebsiteDataModel results = DownloadWebsite(site); ReportWebsiteInfo(results); } }
private async Task RunDownloadParallelAsyncV2() { List <string> websites = PrepData(); List <WebsiteDataModel> websiteList = new List <WebsiteDataModel>(); await Task.Run(() => { Parallel.ForEach <string>(websites, (site) => { WebsiteDataModel result = DownloadWebsite(site); websiteList.Add(result); }); }); foreach (var item in websiteList) { ReportWebsiteInfo(item); } }
private async Task RunDownloadAsync(IProgress <ProgressReport> progress, CancellationToken token) { List <string> websites = PrepData(); List <WebsiteDataModel> sites = new List <WebsiteDataModel>(); ProgressReport report = new ProgressReport(); foreach (string site in websites) { WebsiteDataModel result = await Task.Run(() => DownloadWebsite(site)); sites.Add(result); ReportWebsiteInfo(result); token.ThrowIfCancellationRequested(); report.SitesDownloaded = sites; report.PercentageComplete = (sites.Count * 100) / websites.Count; progress.Report(report); } }
private void ReportWebsiteInfo(WebsiteDataModel data) { resultsWindow.Text += $"{ data.WebsiteUrl } downloaded: { data.WebsiteData.Length } characters long.{ Environment.NewLine }"; }