AsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > AsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッドの意味・解説 

AsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

非同期操作失敗した場合は、ユーザー指定例外発生させます

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

Protected Sub RaiseExceptionIfNecessary
Me.RaiseExceptionIfNecessary
protected void RaiseExceptionIfNecessary ()
protected:
void RaiseExceptionIfNecessary ()
protected void RaiseExceptionIfNecessary ()
protected function RaiseExceptionIfNecessary
 ()
例外例外
例外種類条件

InvalidOperationException

Cancelled プロパティtrue です。

TargetInvocationException

Error プロパティは、非同期操作によって設定されています。InnerException プロパティは、Error への参照保持します

解説解説

継承時の注意 AsyncCompletedEventArgs クラスから独自のクラス派生させている場合読み取り専用プロパティは、プロパティ値を返す前にRaiseExceptionIfNecessary メソッド呼び出す必要がありますコンポーネント非同期ワーカー コード例外Error プロパティ割り当てている場合Cancelled プロパティtrue設定している場合クライアントがその値を読み取ろうとすると、プロパティ例外発生させます。これにより、非同期操作でのエラー原因無効化されている可能性のあるプロパティクライアントアクセスするのを防ぐことができます

使用例使用例

AsyncOperation を使用して非同期操作有効期間追跡するコード例次に示します。このコード例は、System.ComponentModel.AsyncOperationManager クラストピック取り上げているコード例一部分です。

Public Class CalculatePrimeCompletedEventArgs
    Inherits AsyncCompletedEventArgs
    Private numberToTestValue As Integer
 = 0
    Private firstDivisorValue As Integer
 = 1
    Private isPrimeValue As Boolean


    Public Sub New( _
    ByVal numberToTest As Integer,
 _
    ByVal firstDivisor As Integer,
 _
    ByVal isPrime As Boolean,
 _
    ByVal e As Exception, _
    ByVal canceled As Boolean,
 _
    ByVal state As Object)

        MyBase.New(e, canceled, state)
        Me.numberToTestValue = numberToTest
        Me.firstDivisorValue = firstDivisor
        Me.isPrimeValue = isPrime

    End Sub


    Public ReadOnly Property
 NumberToTest() As Integer
        Get
            ' Raise an exception if the operation failed 
            ' or was canceled.
            RaiseExceptionIfNecessary()

            ' If the operation was successful, return 
            ' the property value.
            Return numberToTestValue
        End Get
    End Property


    Public ReadOnly Property
 FirstDivisor() As Integer
        Get
            ' Raise an exception if the operation failed 
            ' or was canceled.
            RaiseExceptionIfNecessary()

            ' If the operation was successful, return 
            ' the property value.
            Return firstDivisorValue
        End Get
    End Property


    Public ReadOnly Property
 IsPrime() As Boolean
        Get
            ' Raise an exception if the operation failed 
            ' or was canceled.
            RaiseExceptionIfNecessary()

            ' If the operation was successful, return 
            ' the property value.
            Return isPrimeValue
        End Get
    End Property
End Class
public class CalculatePrimeCompletedEventArgs
 :
    AsyncCompletedEventArgs
{
    private int numberToTestValue = 0;
    private int firstDivisorValue = 1;
    private bool isPrimeValue;

    public CalculatePrimeCompletedEventArgs(
        int numberToTest,
        int firstDivisor,
        bool isPrime,
        Exception e,
        bool canceled,
        object state) : base(e, canceled, state)
    {
        this.numberToTestValue = numberToTest;
        this.firstDivisorValue = firstDivisor;
        this.isPrimeValue = isPrime;
    }

    public int NumberToTest
    {
        get
        {
            // Raise an exception if the operation failed or 
            // was canceled.
            RaiseExceptionIfNecessary();

            // If the operation was successful, return the 
            // property value.
            return numberToTestValue;
        }
    }

    public int FirstDivisor
    {
        get
        {
            // Raise an exception if the operation failed or 
            // was canceled.
            RaiseExceptionIfNecessary();

            // If the operation was successful, return the 
            // property value.
            return firstDivisorValue;
        }
    }

    public bool IsPrime
    {
        get
        {
            // Raise an exception if the operation failed or 
            // was canceled.
            RaiseExceptionIfNecessary();

            // If the operation was successful, return the 
            // property value.
            return isPrimeValue;
        }
    }
}

import System.*;
import System.Collections.*;
import System.Collections.Specialized.*;
import System.ComponentModel.*;
import System.Threading.*;
<br /><span space="preserve">...</span><br />public
 class CalculatePrimeCompletedEventArgs extends AsyncCompletedEventArgs
{
    private int numberToTestValue = 0;
    private int firstDivisorValue = 1;
    private boolean isPrimeValue;

    public CalculatePrimeCompletedEventArgs(int
 numberToTest, int firstDivisor,
        boolean isPrime, System.Exception e, boolean cancelled, Object state)
    {
        super(e, cancelled, state);
        this.numberToTestValue = numberToTest;
        this.firstDivisorValue = firstDivisor;
        this.isPrimeValue = isPrime;
    } //CalculatePrimeCompletedEventArgs

    /** @property 
     */
    public int get_NumberToTest()
    {
        // Raise an exception if the operation failed or 
        // was cancelled.
        RaiseExceptionIfNecessary();
        // If the operation was successful, return the 
        // property value.
        return numberToTestValue;
    } //get_NumberToTest

    /** @property 
     */
    public int get_FirstDivisor()
    {
        // Raise an exception if the operation failed or 
        // was cancelled.
        RaiseExceptionIfNecessary();
        // If the operation was successful, return the 
        // property value.
        return firstDivisorValue;
    } //get_FirstDivisor

    /** @property 
     */
    public boolean get_IsPrime()
    {
        // Raise an exception if the operation failed or 
        // was cancelled.
        RaiseExceptionIfNecessary();
        // If the operation was successful, return the 
        // property value.
        return isPrimeValue;
    } //get_IsPrime
} //CalculatePrimeCompletedEventArgs
<br /><span space="preserve">...</span><br />public
 class CalculatePrimeCompletedEventArgs extends AsyncCompletedEventArgs
{
    private int numberToTestValue = 0;
    private int firstDivisorValue = 1;
    private boolean isPrimeValue;

    public CalculatePrimeCompletedEventArgs(int
 numberToTest, int firstDivisor,
        boolean isPrime, System.Exception e, boolean cancelled, Object state)
    {
        super(e, cancelled, state);
        this.numberToTestValue = numberToTest;
        this.firstDivisorValue = firstDivisor;
        this.isPrimeValue = isPrime;
    } //CalculatePrimeCompletedEventArgs

    /** @property 
     */
    public int get_NumberToTest()
    {
        // Raise an exception if the operation failed or 
        // was cancelled.
        RaiseExceptionIfNecessary();
        // If the operation was successful, return the 
        // property value.
        return numberToTestValue;
    } //get_NumberToTest

    /** @property 
     */
    public int get_FirstDivisor()
    {
        // Raise an exception if the operation failed or 
        // was cancelled.
        RaiseExceptionIfNecessary();
        // If the operation was successful, return the 
        // property value.
        return firstDivisorValue;
    } //get_FirstDivisor

    /** @property 
     */
    public boolean get_IsPrime()
    {
        // Raise an exception if the operation failed or 
        // was cancelled.
        RaiseExceptionIfNecessary();
        // If the operation was successful, return the 
        // property value.
        return isPrimeValue;
    } //get_IsPrime
} //CalculatePrimeCompletedEventArgs
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AsyncCompletedEventArgs クラス
AsyncCompletedEventArgs メンバ
System.ComponentModel 名前空間
System.ComponentModel.AsyncOperationManager
System.ComponentModel.AsyncOperation
その他の技術情報
イベントベースの非同期パターン実装


このページでは「.NET Framework クラス ライブラリ リファレンス」からAsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からAsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からAsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッド を検索

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

辞書ショートカット

すべての辞書の索引

AsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッドのお隣キーワード
検索ランキング

   

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



AsyncCompletedEventArgs.RaiseExceptionIfNecessary メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS