Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自动增量BackgroundWorker';s进度条_C#_Wpf_Backgroundworker - Fatal编程技术网

C# 自动增量BackgroundWorker';s进度条

C# 自动增量BackgroundWorker';s进度条,c#,wpf,backgroundworker,C#,Wpf,Backgroundworker,如何自动递增ProgressBar而不是调用bgWorker.ReportProgress(x)?(我使用C#,WPF应用程序) 问题是,在BackgroundWorker的工作中,我调用了做大量工作的外部库,并且我希望在库工作时更新ProgressBar。我可以估计运行外部方法所需的时间 我试着使用定时器,但不起作用,因为我无法从另一个线程访问bgWorker 换句话说,我需要这样的东西: bgWorker.StartPercentage = 40; bgWorker.FinishPercen

如何自动递增ProgressBar而不是调用bgWorker.ReportProgress(x)?(我使用C#,WPF应用程序)

问题是,在BackgroundWorker的工作中,我调用了做大量工作的外部库,并且我希望在库工作时更新ProgressBar。我可以估计运行外部方法所需的时间

我试着使用定时器,但不起作用,因为我无法从另一个线程访问bgWorker

换句话说,我需要这样的东西:

bgWorker.StartPercentage = 40;
bgWorker.FinishPercentage = 80;
bgWorker.ProgressBarUpdateTime = 20000; // estimated time needed to run external library
bgWorker.StartProgressBarUpdate();
ExternalLibrary.CallMethod(); // it takes about 20 sec to run this, bgWorker should
     // update ProgressBar, while method is working
bgWorker.ReportProgress(80); // correct ProgressBar value
// do rest of work

我如何才能做到这一点?

您需要为更新进度条的计时器使用单独的后台工作程序

progressBar.BeginAnimation()完全按照我的要求执行@蒂姆提供了一些帮助。

您尝试使用哪个计时器?如果您正在估计时间,为什么要从另一个线程而不是ProgressBar访问bgWorker?看看这里,为什么不干脆用些小时镜呢?如果它不能在20秒内完成,你会怎么做?@tim我试着使用System.Timers.Timer。感谢您的链接,ProgressBar.BeginAnimations解决了我的问题,这正是我想要的。@Blam Hour眼镜不适合我的情况,因为执行时间可能会更长。而且,在任何情况下,使用ProgressBar都比只戴一副眼镜更方便用户。