ReportProgress Method (Int32)
Collapse the table of content
Expand the table of content

BackgroundWorker.ReportProgress Method (Int32)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Raises the ProgressChanged event.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

public void ReportProgress(
	int percentProgress
)

Parameters

percentProgress
Type: System.Int32
The percentage, from 0 to 100, of the background operation that is completed.

ExceptionCondition
InvalidOperationException

The WorkerReportsProgress property is set to false.

If you need the background operation to report on its progress, you can call the ReportProgress method to raise the ProgressChanged event. The WorkerReportsProgress property value must be true, or ReportProgress will throw an InvalidOperationException.

It is up to you to implement a meaningful way of measuring your background operation's progress as a percentage of the total task completed.

The following code example demonstrates the use of the ReportProgress method to report the progress of a background operation to the user. To view the complete code for this sample, see How to use a background worker for Windows Phone 8.


private void bw_DoWork(object sender, DoWorkEventArgs e)
{
    BackgroundWorker worker = sender as BackgroundWorker;

    for (int i = 1; i <= 10; i++)
    {
        if ((worker.CancellationPending == true))
        {
            e.Cancel = true;
            break;
        }
        else
        {
            // Perform a time consuming operation and report progress.
            System.Threading.Thread.Sleep(500);
            worker.ReportProgress(i * 10);
        }
    }
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2016 Microsoft