CancellationPending Property
Collapse the table of content
Expand the table of content

BackgroundWorker.CancellationPending Property

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

Gets a value that indicates whether the application has requested cancellation of a background operation.

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

public bool CancellationPending { get; }

Property Value

Type: System.Boolean
true if the application has requested cancellation of a background operation; otherwise, false. The default is false.

If the CancellationPending property is true, then the CancelAsync method has been called on the BackgroundWorker.

This property is meant for use by the background operation, which should periodically check CancellationPending and stop the background operation when it is set to true.

The following code example demonstrates the use of the CancellationPending property to query a BackgroundWorker about its cancellation state. 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:
© 2017 Microsoft