private static void UpdateProgress() { ProgressBar.Invoke(new InvokeDelegate(SetProgressBarValue), (int)((double)Status.CurrentProgress * 10000 / Status.TotalProgress)); if (Status.TotalProgress > 0) { ProgressLabel.Invoke(new InvokeDelegate(SetProgressLabel), string.Format("{0}/{1}", Status.CurrentProgress, Status.TotalProgress)); PercentageLabel.Invoke(new InvokeDelegate(SetPercentageLabel), string.Format("{0:0.##}%", (double)Status.CurrentProgress * 100 / Status.TotalProgress)); TimeUsageLabel.Invoke(new InvokeDelegate(SetTimeUsageLabel), "已用时间:" + TimeSpan.FromMilliseconds(Timer.ElapsedMilliseconds).ToString(@"hh\:mm\:ss\.fff")); var time = (double)Timer.ElapsedMilliseconds * (Status.TotalProgress - Status.CurrentProgress) / Status.CurrentProgress; if (time.HasValue()) { TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "估计剩余时间:" + TimeSpan.FromMilliseconds(time).ToString(@"hh\:mm\:ss\.fff")); } else { TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "等待开始"); } } else { StatusLabel.Invoke(new InvokeDelegate(SetStatusLabel), Status.CurrentStatus); ProgressLabel.Invoke(new InvokeDelegate(SetProgressLabel), "等待开始"); PercentageLabel.Invoke(new InvokeDelegate(SetPercentageLabel), "等待开始"); TimeUsageLabel.Invoke(new InvokeDelegate(SetTimeUsageLabel), "等待开始"); TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "等待开始"); } }
public static void RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { StatusLabel.Invoke(new InvokeDelegate(SetStatusLabel), "等待开始"); ProgressLabel.Invoke(new InvokeDelegate(SetProgressLabel), "等待开始"); PercentageLabel.Invoke(new InvokeDelegate(SetPercentageLabel), "等待开始"); TimeUsageLabel.Invoke(new InvokeDelegate(SetTimeUsageLabel), "等待开始"); TimeEstimationLabel.Invoke(new InvokeDelegate(SetTimeEstimationLabel), "等待开始"); ProgressBar.Invoke(new InvokeDelegate(SetProgressBarValue), 0); //ProgressBar.Invoke(new InvokeDelegate(SetProgressBarMaximum), 100); //Console.WriteLine("Worker Reset"); WorkerInBusy.Set(); }