by luisabreu via LA.NET [EN] on 5/22/2009 10:12:47 AM
In the last post, we’ve talked about several methods that allow us to wait on one or more kernel objects until they transition into the signaled state. Today we’re going to take a look at the last method (exposed by the WaitHandle class) that we can use for waiting on an object: the SignalAndWait method. You can use one of the overloads of this method when you need to signal an existing kernel object and wait on another one until it gets into the signaled state. The coolest thing about this method is that the signaling and waiting is performed atomically! Signaling the object performs the expected operation:
It’s also important to keep in mind that you might end up getting exceptions. For instance, if you’re calling this method and you’re signaling a semaphore that is already “full”, then you’ll end up getting and InvalidOperationException.
Whenever you need to signal a kernel object and wait on another, you should always use this method to ensure that the operations are performed atomically.
And that’s all for today. On the next post we’ll start looking at the high level sync primitives. Keep tuned for more.
Original Post: Multithreading: signaling and waiting
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.