AsyncResult.AsyncState プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)



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
// 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); }
// Asynchronous Callback method. 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( "Simple::SomeMethod (AsyncCallback): Result of " ); Console::WriteLine( " {0} in SampleSynchronized::Square is {1} ", value, result ); }
// Asynchronous Callback method. public static void MyCallback(IAsyncResult ar) { // Obtains the last parameter of the delegate call. SampSyncSqrDelegate sampDelg = (SampSyncSqrDelegate)ar.get_AsyncState(); // Obtains return value from the delegate call using EndInvoke. AsyncResult aResult = (AsyncResult)ar; SampSyncSqrDelegate temp = (SampSyncSqrDelegate)(aResult.get_AsyncDelegate()); int threadId = AppDomain.GetCurrentThreadId(); int result = temp.EndInvoke(ar); Console.Write("Simple.SomeMethod (AsyncCallback): Result of "); Console.WriteLine("{0} in SampleSynchronized.Square is {1} ", (Int32)value, (Int32)result); } //MyCallback

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- AsyncResult.AsyncState プロパティのページへのリンク