Search code examples
c#wpfprogress-barbackgroundworker

BackgroundWorker.ReportProgress breaks out of method


It seems like wherever I call ReportProgress on my BackgroundWorker, the processing of that method stops so my work never finishes. Example:

int numQuals = this.Model.Names.Count();
int currentQual = 0;
int fivePercent = (int)(numQuals * .05);
foreach (var qualName in this.Model.Names)
{
    if ((worker != null) && ((currentQual % fivePercent == 0)))
    {
        worker.ReportProgress((int) (((float)++currentQual / numQuals) * 100));
    }

    // This next line never processes. I can debug and it will 
    // break at the ReportProgress line but won't ever break here
    this.myContainer.Add(...
}

Does anyone have any idea why this is?


Solution

  • Have you set worker.WorkerReportsProgress=true ? Otherwise, the background worker will terminate with an exception and the work will not be fullfilled.