Implementing Asynchronous Methods in Remoting Applns.
Introduction
Point to Remember
Steps Involved
1. Create an instance of an object that can receive a remote call to a method.
2. Wrap that instance method with an AsyncDelegate method.
3. Wrap the remote method with another delegate.
4. Call the BeginInvoke method on the second delegate, passing any arguments, the AsyncDelegate method, and some object to hold the state.
5. Wait for the server object to call your callback method.
Code Sample
C#
VB.NET
' Create a delegate to the method that will be executed asynchronously Dim remoteDel As New MyAsyncDelegate(AddressOf obj.LongCall)
When implementing asynchronous programming in a .NET Remoting application the following points are considered,
To complete the asynchronous programming in remote application, complete the following steps:
// Create an instance of the class that can receive remote calls MyRemoteObject remoteObj = new MyRemoteObject(); // Create delegate to a method that is executed when async method // finishes execution. AsyncCallback remoteMethod = new AsyncCallback(remoteObj.CallBackMethod); // Create a delegate to the method that will be executed asynchronously MyAsyncDelegate remoteDel = new MyAsyncDelegate(obj.LongCall);
// Begin the invocation of the asynchronous method. remoteDel.BeginInvoke(remoteMethod,nothing);
Create an instance of the class that can receive remote calls Dim remoteObj as New MyRemoteObject()
' Create delegate to a method that is executed when async method finishes execution. Dim remoteMethod as New AsyncCallback(AddressOf remoteObj.CallBackMethod)
' Define a delegate to a method Delegate Sub MyAsyncDelegate()
' Begin the invocation of the asynchronous method. remoteDel.BeginInvoke(remoteMethod,nothing)