4.9. Synchronize the Execution of Multiple Threads Using an Event

Problem

You need a mechanism to synchronize the execution of multiple threads in order to coordinate their activities or access to shared resources.

Solution

Use the EventWaitHandle, AutoResetEvent, and ManualResetEvent classes from the System.Threading namespace.

How It Works

The EventWaitHandle, AutoResetEvent, and ManualResetEvent classes provide similar functionality. The EventWaitHandle class is the base class from which the AutoResetEvent and ManualResetEvent classes are derived. EventWaitHandle inherits directly from System.Threading.WaitHandle and allows you to create named events. All three event classes allow you to synchronize multiple threads by manipulating the state ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach 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.