private async void asyncExecuteBtn_Click(object sender, EventArgs e) { var progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += (sender1, e1) => { progressBar1.Value = e1.PercentageComplete; PrintResults(e1.SitesDownloaded); }; resultTBox.Text = ""; Stopwatch watch = Stopwatch.StartNew(); try { cts = new CancellationTokenSource(); var results = await DemoMethods.RunDownloadAsync(progress, cts.Token); PrintResults(results); } catch (OperationCanceledException) { resultTBox.Text += $"The async donwload was cancelled. { Environment.NewLine }"; } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; resultTBox.Text += $"Total execution time: { elapsedMs }"; }
private void parallelSyncExecute_Click(object sender, EventArgs e) { resultTBox.Text = ""; Stopwatch watch = Stopwatch.StartNew(); var results = DemoMethods.RunDownloadParallelSync(); PrintResults(results); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; resultTBox.Text += $"Total execution time: { elapsedMs }"; }
private async void parallelAsyncExecute2_Click(object sender, EventArgs e) { var progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += (sender1, e1) => { progressBar1.Value = e1.PercentageComplete; PrintResults(e1.SitesDownloaded); }; resultTBox.Text = ""; Stopwatch watch = Stopwatch.StartNew(); var results = await DemoMethods.RunDownloadParallelAsync2(progress); PrintResults(results); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; resultTBox.Text += $"Total execution time: { elapsedMs }"; }