public ProgressStatistic() { StartingTime = DateTime.MinValue; FinishingTime = DateTime.MinValue; _progressChangedArgs = new ProgressEventArgs(this); //Event args can be cached }
private void updateProgressBar(object sender, ProgressEventArgs progressEventArgs) { if (progressEventArgs == null) { return; } var stat = progressEventArgs.ProgressStatistic; if (stat.HasFinished || double.IsNaN(stat.Progress)) { _viewModel.ProgressCompleted = 0; _viewModel.EstimatedCompletionTime = DateTime.MinValue; _viewModel.AverageSpeed = 0; _viewModel.CurrentSpeed = 0; return; } _viewModel.ProgressCompleted = (decimal) (stat.Progress*_viewModel.ProgressBarResolution); _viewModel.EstimatedCompletionTime = stat.EstimatedFinishingTime; _viewModel.AverageSpeed = (long) stat.AverageBytesPerSecond; _viewModel.CurrentSpeed = (long) stat.CurrentBytesPerSecond; }
private void UpdateProgressBar(object sender, ProgressEventArgs progressEventArgs) { var stat = progressEventArgs.ProgressStatistic; if (stat.HasFinished || double.IsNaN(stat.Progress)) { progressBar.SafeInvoke(x => x.Value = 0); etaLabel.SafeInvoke(x => x.Text = "ETA"); return; } progressBar.SafeInvoke(x => x.Maximum = ProgressBarResolution); progressBar.SafeInvoke(x => x.Value = (int) (stat.Progress * ProgressBarResolution)); etaLabel.SafeInvoke(x => x.Text = $"ETA: {stat.EstimatedFinishingTime}"); }