Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

AsyncResult.AsyncDelegate Property

Gets the delegate object on which the asynchronous call was invoked.

Namespace: System.Runtime.Remoting.Messaging
Assembly: mscorlib (in mscorlib.dll)

public virtual Object AsyncDelegate { get; }
/** @property */
public Object get_AsyncDelegate ()

public function get AsyncDelegate () : Object

Property Value

The delegate object on which the asynchronous call was invoked.

The AsyncDelegate property can be cast to the actual class of the user-defined delegate.

For example, if the user-defined delegate is of type MyDelegate, in order to access MyDelegate.EndInvoke, the asynchronous delegate must be cast to MyDelegate. The MyDelegate.EndInvoke can be called in the async callback function (of type AsyncCallback) to obtain the results of the originally submitted MyDelegate.BeginInvoke.

The following code example demonstrates how to get the delegate object on which the asynchronous call was invoked from the AsyncResult. For the complete example code, see the example for the AsyncResult class.

// 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.
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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.