Search code examples
c#wpfbackgroundworker

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?


Solution

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