O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Wait for Several Asynchronous Calls to Complete

Problem

You want to call multiple procedures asynchronously and suspend further processing until they are all complete.

Solution

Retrieve the WaitHandle for each call, and use the shared WaitHandle.WaitAll method.

Discussion

When you call the BeginInvoke method, you receive an IAsyncResult object that allows you to check the status of the thread and complete the request. In addition, the IAsyncResult interface defines an AsyncWaitHandle property that allows you to retrieve a WaitHandle for the asynchronous request.

The WaitHandle class defines three methods: WaitAll, WaitAny, and WaitOne. You can use the shared WaitAll method with an array of WaitHandle objects to wait for a group of asynchronous tasks ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required