Implementing Aysnchronous Methods in Remoting Applications

Implementing Asynchronous Methods in Remoting Applns.

 

Introduction
Implementing asynchronous programming in remoting applications is similar to implementing asynchronous programming in a single application domain or context. You just need to configure asynchronous method calls according to the requirements of .NET Remoting.

 

Point to Remember

 


When implementing asynchronous programming in a .NET Remoting application the following points are considered,

  • The caller decides whether a particular remote call is asynchronous.

  • Remote types do not have to support asynchronous behavior by their clients.

  • Need to complete type safety.

  • Must use the System.Threading objects appropriately to wait or synchronize your methods.

Steps Involved

 


To complete the asynchronous programming in remote application, complete the following steps:

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#

 
// 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);

 

 

 

 

 

 

 

 

 

 

 

VB.NET

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()

 

' Create a delegate to the method that will be executed asynchronously Dim remoteDel As New MyAsyncDelegate(AddressOf obj.LongCall)

' Begin the invocation of the asynchronous method. remoteDel.BeginInvoke(remoteMethod,nothing)
 
 
 
 
 

 

 


















Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish