private void Progress_ProgressChanged(object sender, ProgressModel e) { progrBar.Value = e.Progess; resultsWindow.Text += e.WebSiteStatus; if (progrBar.Value == 100) { stopwatch.Stop(); var elapsedMs = stopwatch.ElapsedMilliseconds; resultsWindow.Text += $"Total execution time: { elapsedMs }"; } }
private static void TaskDone(Task <WebsiteDataModel> arg) { _doneSiteCont++; if (_progress != null) { ProgressModel progressModel = new ProgressModel(); progressModel.Progess = _doneSiteCont * 100 / _totalSiteCount; WebsiteDataModel data = arg.Result; progressModel.WebSiteStatus = $"{ data.WebsiteUrl } downloaded: { data.WebsiteData.Length } characters long in {data.time_ms} ms .{ Environment.NewLine }"; _progress.Report(progressModel); } }
public static void DownloadWebsite(string websiteURL, IProgress <ProgressModel> progress) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteUrl = websiteURL; var watch = System.Diagnostics.Stopwatch.StartNew(); output.WebsiteData = client.DownloadString(websiteURL); watch.Stop(); output.time_ms = watch.ElapsedMilliseconds; _doneSiteCont++; ProgressModel progressModel = new ProgressModel(); progressModel.Progess = _doneSiteCont * 100 / _totalSiteCount; progressModel.WebSiteStatus = $"{ websiteURL } downloaded: { output.WebsiteData.Length } characters long in {output.time_ms} ms .{ Environment.NewLine }"; _progress.Report(progressModel); }