4.6. Execute a Method by Signaling a WaitHandle Object

Problem

You need to execute one or more methods automatically when an object derived from System. Threading.WaitHandle is signaled.

Solution

Declare a method containing the code you want to execute. The method's signature must match that defined by the System.Threading.WaitOrTimerCallback delegate. Using the SharedThreadPool. RegisterWaitForSingleObject method, register the method to execute and the WaitHandle object that will trigger execution when signaled.

How It Works

You can use classes derived from the WaitHandle class to trigger the execution of a method. Using the RegisterWaitForSingleObject method of the ThreadPool class, you can register a WaitOrTimerCallback delegate instance ...

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.