Wait Handles

With a wait handle, you can cause your program to wait until any one request in a batch of requests is complete or until all the requests have finished. All you need to do is use one of the shared methods of the System.Threading.Wait­Handle class and provide it with an array of WaitHandle objects. You can retrieve a WaitHandle from the IAsyncResult.AsyncWaitHandle property.

Example 6-5 shows an example that starts several XML Web service methods asynchronously and waits for them all to complete. Note that for this code to work as written, you need to import the System.Threading namespace.

Example 6-5. Waiting for multiple asynchronous methods to complete

‘ Call three methods asynchronously. Dim Async1, Async2, Async3 As IAsyncResult ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.