private async void executeASync_Click(object sender, RoutedEventArgs e) { Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += ReportProgress; executeASync.IsEnabled = false; executeASync.Content = "Running..."; var watch = System.Diagnostics.Stopwatch.StartNew(); try { var results = await DemoMethods.RunDownloadASync(progress, cts.Token); PrintResults(results); } catch (OperationCanceledException) { resultsWindow.Text += $"The async download was cancelled. {Environment.NewLine} "; cts = new CancellationTokenSource(); } watch.Stop(); var elapsedMS = watch.ElapsedMilliseconds; resultsWindow.Text += $"Total execution time: { elapsedMS}"; executeASync.IsEnabled = true; executeASync.Content = "Async Execute"; }
//>>>>>>>>>>>>>>>>> //Code is placed here for simplicity purposes. Code should not be going in the main window class //>>>>>>>>>>>>>>>>> private void executeSync_Click(object sender, RoutedEventArgs e) { var watch = System.Diagnostics.Stopwatch.StartNew(); var results = DemoMethods.RunDownloadSync(); PrintResults(results); watch.Stop(); var elapsedMS = watch.ElapsedMilliseconds; resultsWindow.Text += $"Total execution time: { elapsedMS}"; }
private async void executeParallelASync_Click(object sender, RoutedEventArgs e) { Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += ReportProgress; executeParallelASync.IsEnabled = false; executeParallelASync.Content = "Running..."; var watch = System.Diagnostics.Stopwatch.StartNew(); var results = await DemoMethods.RunDownloadParallelAsyncV2(progress); PrintResults(results); watch.Stop(); var elapsedMS = watch.ElapsedMilliseconds; resultsWindow.Text += $"Total execution time: { elapsedMS}"; executeParallelASync.IsEnabled = true; executeParallelASync.Content = "Parallel Async Execute"; }