Export (0) Print
Expand All

AsyncResult.AsyncDelegate Property

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

[Visual Basic]
Public Overridable ReadOnly Property AsyncDelegate As Object
[C#]
public virtual object AsyncDelegate {get;}
[C++]
public: __property virtual Object* get_AsyncDelegate();
[JScript]
public function get AsyncDelegate() : Object;

Property Value

The delegate object on which the asynchronous call was invoked.

Remarks

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.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
' 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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

AsyncResult Class | AsyncResult Members | System.Runtime.Remoting.Messaging Namespace | Asynchronous Delegates

Show:
© 2014 Microsoft