private async void ExecuteAsync_Click(object sender, RoutedEventArgs e) { resultsWindow.Text = ""; cts.Dispose(); // Clean up old token source.... cts = new CancellationTokenSource(); // "Reset" the cancellation token source.. Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += ReportProgress; 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}"; } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; resultsWindow.Text += $"Total execution time was: {elapsedMs}{Environment.NewLine}"; }
private async void Button_Async_Click(object sender, RoutedEventArgs e) { asyncBtn.IsEnabled = false; var sw = new Stopwatch(); sw.Start(); var result = await DemoMethods.RunDownloadAsync(); sw.Stop(); PrintResults(result); output.Text += $"Total time: " + sw.Elapsed; asyncBtn.IsEnabled = true; }
private async void executeAsync_Click(object sender, RoutedEventArgs e) { var progress = new Progress <ProgressReportModel>(); progress.ProgressChanged += ReportProgress; 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 }"; } watch.Stop(); var elaspedMs = watch.ElapsedMilliseconds; resultsWindow.Text += $"Total execution time: {elaspedMs}"; }
private async Task ExecuteLongProcessAsync() { IProgress <ProgressReportModel> progress = new Progress <ProgressReportModel>(); await DemoMethods.RunDownloadAsync(progress, _cts.Token); }