protected override async Task ExecuteCoreAsync(object parameter, CancellationToken cancellationToken) { this.viewModel.IsRunning = true; try { var progress = new Microsoft.Progress <TestRunProgress>(value => this.viewModel.CurrentProgress = value); await this.viewModel.runner.RunTestsAsync(this.viewModel.Tests, progress, cancellationToken); } finally { this.viewModel.IsRunning = false; } }
private async void downloadButton_Click(object sender, RoutedEventArgs e) { var url = UrlTextBox.Text; CancelButton.IsEnabled = true; ProgressBar.Visibility = Visibility.Visible; try { var progress = new Microsoft.Progress <double>(); progress.ProgressChanged += (sender1, value) => { ProgressBar.Value = value; var totalReadMb = GetMegabytes(_totalReadBytes); var totalMb = GetMegabytes(_totalBytes); TotalSizeLabel.Content = $"{totalReadMb:0.00} / {totalMb:0.00}"; }; await DownloadFileAsync(url, progress, _cancellationToken.Token); CancelButton.IsEnabled = false; ProgressBar.Visibility = Visibility.Hidden; TotalSizeLabel.Content = string.Empty; MessageBox.Show(Properties.Resources.FileWasDownloadedMessage, Properties.Resources.InformationCaption, MessageBoxButton.OK, MessageBoxImage.Information); } catch (TaskCanceledException) { CancelButton.IsEnabled = false; ProgressBar.Visibility = Visibility.Hidden; TotalSizeLabel.Content = string.Empty; _cancellationToken = new CancellationTokenSource(); MessageBox.Show(Properties.Resources.FileDownloadingWasCanceledMessage, Properties.Resources.InformationCaption, MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception exception) { MessageBox.Show(exception.Message, Properties.Resources.ErrorCaption, MessageBoxButton.OK, MessageBoxImage.Error); } }