简体   繁体   中英

Auto increment BackgroundWorker 's ProgressBar

How to autoincrement ProgressBar instead of calling bgWorker.ReportProgress(x)? (I use C#, WPF Application).

Problem is that within BackgroundWorker's work I call external library that do a lot of work and I want to update ProgressBar while library working. I can estimate time needed for running external method.

I tried using Timer, but that doesn't work, because I can't access to bgWorker from another thread.

In other words, I need something like this:

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

How can I do that?

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

progressBar.BeginAnimation() do exactly what I want. @tim provided link that helped me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM