Nota: esta propiedad es nueva en la versión 2.0 de .NET Framework.
Obtiene un valor que indica si la aplicación ha solicitado la cancelación de una operación en segundo plano.
Espacio de nombres: System.ComponentModel
Ensamblado: System (en system.dll)
Visual Basic (Declaración)
Public ReadOnly Property CancellationPending As Boolean
Dim instance As BackgroundWorker
Dim value As Boolean
value = instance.CancellationPending
public bool CancellationPending { get; }
public:
property bool CancellationPending {
bool get ();
}
/** @property */
public boolean get_CancellationPending ()
public function get CancellationPending () : boolean
Valor de propiedad
true si la aplicación ha solicitado la cancelación de una operación en segundo plano; de lo contrario, false. El valor predeterminado es false.
Si CancellationPending es true, significa que se ha llamado al método CancelAsync en el objeto BackgroundWorker.
Esta propiedad está pensada para que la utilice el subproceso de trabajo, que debería comprobar CancellationPending periódicamente y anular la operación en segundo plano cuando se establezca en true.
En el ejemplo de código siguiente se muestra el uso de la propiedad CancellationPending para consultar el estado de cancelación de BackgroundWorker. Este ejemplo de código forma parte de un ejemplo más extenso referente a la clase BackgroundWorker.
' Abort the operation if the user has canceled.
' Note that a call to CancelAsync may have set
' CancellationPending to true just after the
' last invocation of this method exits, so this
' code will not have the opportunity to set the
' DoWorkEventArgs.Cancel flag to true. This means
' that RunWorkerCompletedEventArgs.Cancelled will
' not be set to true in your RunWorkerCompleted
' event handler. This is a race condition.
If worker.CancellationPending Then
e.Cancel = True
Else
If n < 2 Then
result = 1
Else
result = ComputeFibonacci(n - 1, worker, e) + _
ComputeFibonacci(n - 2, worker, e)
End If
' Report progress as a percentage of the total task.
Dim percentComplete As Integer = _
CSng(n) / CSng(numberToCompute) * 100
If percentComplete > highestPercentageReached Then
highestPercentageReached = percentComplete
worker.ReportProgress(percentComplete)
End If
End If
// Abort the operation if the user has canceled.
// Note that a call to CancelAsync may have set
// CancellationPending to true just after the
// last invocation of this method exits, so this
// code will not have the opportunity to set the
// DoWorkEventArgs.Cancel flag to true. This means
// that RunWorkerCompletedEventArgs.Cancelled will
// not be set to true in your RunWorkerCompleted
// event handler. This is a race condition.
if (worker.CancellationPending)
{
e.Cancel = true;
}
else
{
if (n < 2)
{
result = 1;
}
else
{
result = ComputeFibonacci(n - 1, worker, e) +
ComputeFibonacci(n - 2, worker, e);
}
// Report progress as a percentage of the total task.
int percentComplete =
(int)((float)n / (float)numberToCompute * 100);
if (percentComplete > highestPercentageReached)
{
highestPercentageReached = percentComplete;
worker.ReportProgress(percentComplete);
}
}
// Abort the operation if the user has cancelled.
// Note that a call to CancelAsync may have set
// CancellationPending to true just after the
// last invocation of this method exits, so this
// code will not have the opportunity to set the
// DoWorkEventArgs.Cancel flag to true. This means
// that RunWorkerCompletedEventArgs.Cancelled will
// not be set to true in your RunWorkerCompleted
// event handler. This is a race condition.
if ( worker->CancellationPending )
{
e->Cancel = true;
}
else
{
if ( n < 2 )
{
result = 1;
}
else
{
result = ComputeFibonacci( n - 1, worker, e ) + ComputeFibonacci( n - 2, worker, e );
}
// Report progress as a percentage of the total task.
int percentComplete = (int)((float)n / (float)numberToCompute * 100);
if ( percentComplete > highestPercentageReached )
{
highestPercentageReached = percentComplete;
worker->ReportProgress( percentComplete );
}
}
// Abort the operation if the user has cancelled.
// Note that a call to CancelAsync may have set
// CancellationPending to true just after the
// last invocation of this method exits, so this
// code will not have the opportunity to set the
// DoWorkEventArgs.Cancel flag to true. This means
// that RunWorkerCompletedEventArgs.Cancelled will
// not be set to true in your RunWorkerCompleted
// event handler. This is a race condition.
if (worker.get_CancellationPending()) {
e.set_Cancel(true);
}
else {
if (n < 2) {
result = 1;
}
else {
result = ComputeFibonacci(n - 1, worker, e)
+ ComputeFibonacci(n - 2, worker, e);
}
// Report progress as a percentage of the total task.
int percentComplete=(int)((float)(n)/(float)(numberToCompute)* 100);
if (percentComplete > highestPercentageReached) {
highestPercentageReached = percentComplete;
worker.ReportProgress(percentComplete);
}
}
Windows 98, Windows 2000 SP4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter Edition
.NET Framework no admite todas las versiones de cada plataforma. Para obtener una lista de las versiones admitidas, vea Requisitos del sistema.
.NET Framework
Compatible con: 2.0