
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Get the Naming Rights for Your Events
|
1059
Mel.CallWaitress( );
}
Discussion
There are two types of events, AutoResetEvent and ManualResetEvent. There are two
main differences between the events. The first is that
AutoResetEvents release only
one of the threads that are waiting on the event while a
ManualResetEvent will release
all of them when
Set is called. The second difference is that when Set is called on an
AutoResetEvent, it is automatically reset to a nonsignaled state while the ManualResetEvent
is left in a signaled state until the Reset method is called.
See Also
See the “AutoResetEvent” and “ManualResetEvent” topics in the MSDN documen-
tation and Programming Applications for Microsoft Windows, (Fourth Edition).
18.13 Get the Naming Rights for Your Events
Problem
You want to have code running in worker threads, or in other processes or AppDomains,
to be able to wait on an event.
Solution
Use the EventWaitHandle class, new to the 2.0 Framework. With it, you can create a
named event that will allow any code running on the local machine to find and wait
on the event.
AutoResetEvent and ManualResetEvent are excellent for signaling events
in threaded code and even between AppDomains if you are willing to go through the
hassle of passing the event reference around. Why bother? Both of