如何自动增加 ProgressBar 而不是调用 bgWorker.ReportProgress(x)?(我使用 C#,WPF 应用程序)。
问题是在 BackgroundWorker 的工作中,我调用了做大量工作的外部库,并且我想在库工作时更新 ProgressBar。我可以估计运行外部方法所需的时间。
我尝试使用 Timer,但这不起作用,因为我无法从另一个线程访问 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
我怎样才能做到这一点?