This documentation is archived and is not being maintained.

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

Not applicable.

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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Show: