In other words I have a thread that starts and calls waitHandle.Set()
multiple times. Then I start several threads and each is waiting on that WaitHandle
. Will X of the them be signaled where X is the number of times the original thread called waitHandle.Set()
?
Is there a structure that supports what I'm trying to accomplish more closely?
Maybe, but probably not.
An event can only be set or unset, if there is nothing to unset the event then repeated calls to Set will not change its state, unless it is an auto-reset event and there is at least one thread waiting on it. With a manual reset event any threads waiting (or starting to wait) will be released until something unsets the event.
I think you will actually want a semaphore, which does have a count and supports setting n times to release n threads (even if some of those threads only start waiting after some of the calls to set).
It depends on the EventResetMode
. If it is set to EventResetMode.AutoReset
it will only release one thread. If it is 'EventResetMode.ManualReset' however it will release all threads blocked on the event.
Semaphore.Release(Int)
Where Int is the count would be one way to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With