The call to
WaitHandle.WaitAll
always block the calling thread if at least one the the event wait handles is in non-signaled state.
You simply don't notice it or never reach blocking state because all threads complete very quickly. You never know which thread reach certain point of execution first, and an attempt to rely on the order of execution is called
race condition (
http://en.wikipedia.org/wiki/Race_condition[
^]).
To check this up, add a call to
System.Threading.Thread.Sleep
before the line "
resetEvents[index].Set()
;" — you will observe the blocking is sleep time is long enough.
I
don't say such call to
Sleep
should be use in real-life programming. Just the opposite:
trying to resolve any logical problem with delay would be absolutely incorrect. You can do it just for experimental purpose.
As all you code does not seem to have any practical sense, I assume you do it all for experimental purposes yourself. Well, it's good to practice things; good luck.
—SA