次の方法で共有


AsyncResult.AsyncState プロパティ

BeginInvoke メソッドの呼び出しの最後のパラメータに指定されたオブジェクトを取得します。

Public Overridable ReadOnly Property AsyncState As Object  _   Implements IAsyncResult.AsyncState
[C#]
public virtual object AsyncState {get;}
[C++]
public: __property virtual Object* get_AsyncState();
[JScript]
public function get AsyncState() : Object;

プロパティ値

BeginInvoke メソッドの呼び出しの最後のパラメータに指定されたオブジェクト。

実装

IAsyncResult.AsyncState

解説

BeginInvoke メソッドの詳細については、「 非同期デリゲート 」を参照してください。

使用例

[Visual Basic, C#, C++] AsyncState プロパティを使用して、 BeginInvoke メソッドの呼び出しの最後のパラメータを取得する方法を次のコード例に示します。プログラム例の全体については、 AsyncResult クラスのトピックの例を参照してください。

 
' Asynchronous Callback method.
Public Shared Sub MyCallback(ar As IAsyncResult)
   ' Obtains the last parameter of the delegate call.
   Dim value As Integer = Convert.ToInt32(ar.AsyncState)
   
   ' Obtains return value from the delegate call using EndInvoke.
   Dim aResult As AsyncResult = CType(ar, AsyncResult)
   Dim temp As SampSyncSqrDelegate = CType(aResult.AsyncDelegate, SampSyncSqrDelegate)
   Dim result As Integer = temp.EndInvoke(ar)
   
   Console.Write("Simple.SomeMethod (AsyncCallback): Result of ")
   Console.WriteLine("{0} in SampleSynchronized.Square is {1} ", value, result)
End Sub 'MyCallback  

[C#] 
// Asynchronous Callback method.
public static void MyCallback(IAsyncResult ar) {

    // Obtains the last parameter of the delegate call.
    int value = Convert.ToInt32(ar.AsyncState);

    // Obtains return value from the delegate call using EndInvoke.
    AsyncResult aResult = (AsyncResult)ar;
    SampSyncSqrDelegate temp = (SampSyncSqrDelegate)aResult.AsyncDelegate;
    int result = temp.EndInvoke(ar);

    Console.Write("Simple.SomeMethod (AsyncCallback): Result of ");
    Console.WriteLine("{0} in SampleSynchronized.Square is {1} ", value, result);
}

[C++] 
// Asynchronous Callback method.
public:
static void MyCallback(IAsyncResult* ar) 
{
    // Obtains the last parameter of the delegate call.
    int value = Convert::ToInt32(ar->AsyncState);

    // Obtains return value from the delegate call using EndInvoke.
    AsyncResult* aResult = dynamic_cast<AsyncResult*>(ar);
    SampSyncSqrDelegate* temp = static_cast<SampSyncSqrDelegate*>(aResult->AsyncDelegate);
    int result = temp->EndInvoke(ar);

    Console::Write(S"Simple::SomeMethod (AsyncCallback): Result of ");
    Console::WriteLine(S" {0} in SampleSynchronized::Square is {1} ", __box(value), __box(result));
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

AsyncResult クラス | AsyncResult メンバ | System.Runtime.Remoting.Messaging 名前空間 | 非同期デリゲート