Backgroundworker won't report progress Backgroundworker won't report progress wpf wpf

Backgroundworker won't report progress


You need to break your DoWork method down into reportable progress and then call ReportProgress.

Take for example the following:

private void Something_DoWork(object sender, DoWorkEventArgs e) {    // If possible, establish how much there is to do    int totalSteps = EstablishWorkload();    for ( int i=0; i<totalSteps; i++)    {        // Do something...        // Report progress, hint: sender is your worker        (sender as BackgroundWorker).ReportProgress((int)(100/totalSteps)*i, null);    }}

If your work can't be predetermined, try adding your own percentages:

private void Something_DoWork(object sender, DoWorkEventArgs e) {    // some work    (sender as BackgroundWorker).ReportProgress(25, null);    // some work    (sender as BackgroundWorker).ReportProgress(50, null);    // some work    (sender as BackgroundWorker).ReportProgress(60, null);    // some work    (sender as BackgroundWorker).ReportProgress(99, null);}


Modify the WorkReportProgress property of the backgroundworker object to true either in the properties window or in code.