private async Task <DemoClass> DownloadWebsiteAsync(string websiteURL) { DemoClass output = new DemoClass(); WebClient client = new WebClient(); output.WebsiteUrl = websiteURL; output.WebsiteData = await client.DownloadStringTaskAsync(websiteURL); return(output); }
private DemoClass DownloadWebsite(string websiteURL) { DemoClass output = new DemoClass(); WebClient client = new WebClient(); output.WebsiteUrl = websiteURL; output.WebsiteData = client.DownloadString(websiteURL); return(output); }
//Sync Download Methods private void RunDownload() { List <string> websites = PrepData(); LogTxtBox.Text = ""; foreach (var site in websites) { DemoClass results = DownloadWebsite(site); ReportWebsiteInfo(results); } }
//Async Download Methods private async Task <List <DemoClass> > RunDownloadAsync(IProgress <ProgressReportModel> progress) { List <string> websites = PrepData(); List <DemoClass> output = new List <DemoClass>(); ProgressReportModel report = new ProgressReportModel(); LogTxtBox.Text = ""; foreach (var site in websites) { DemoClass result = await DownloadWebsiteAsync(site); output.Add(result); report.WebsitesDownloaded = output; report.Percentage = (output.Count * 100) / websites.Count; progress.Report(report); // ReportWebsiteInfo(results); } return(output); }
//Shared Methods private void ReportWebsiteInfo(DemoClass data) { LogTxtBox.Text += $"{data.WebsiteUrl} downloaded: {data.WebsiteData.Length} characters long. {Environment.NewLine}"; }