BackgroundWorker.CancellationPending プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > BackgroundWorker.CancellationPending プロパティの意味・解説 

BackgroundWorker.CancellationPending プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

アプリケーションバックグラウンド操作キャンセル要求したかどうかを示す値を取得します

名前空間: System.ComponentModel
アセンブリ: System (system.dll 内)
構文構文

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

プロパティ
アプリケーションバックグラウンド操作キャンセル要求した場合trueそれ以外場合false既定値false です。

解説解説

CancellationPendingtrue場合、BackgroundWorker に対して CancelAsync メソッド呼び出されています。

このプロパティは、ワーカー スレッド使用するためのものです。ワーカー スレッドは、CancellationPending定期的にチェックし、このプロパティtrue設定されている場合バックグラウンド操作中止します

使用例使用例

CancellationPending プロパティ使用してキャンセル状態について BackgroundWorker問い合わせるコード例次に示します。このコード例は、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);
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

BackgroundWorker.CancellationPending プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



BackgroundWorker.CancellationPending プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS