Callbacks

Callbacks are one of the preferred ways to handle asynchronous calls because they simplify your code and eliminate the overhead of having to continuously poll a request that is in progress to see whether it has completed. The second-to-last parameter of the BeginInvoke method (or BeginMethodName in an XML Web service proxy class) accepts a reference to the method that you want triggered when the method call is complete.

To use a callback successfully, your callback method must have the same signature as the System.AsyncCallback delegate. That means it needs to accept a single IAsyncResult parameter. Here’s an example:

Public Sub AsyncCallback(ByVal ar As IAsyncResult)     ‘ (This code will be triggered when the method call is complete.) ...

Get Microsoft® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.