AutoResetEvent... use WaitOne or WaitAll?

  • Thread starter Thread starter buu
  • Start date Start date
B

buu

If I have a multithreaded app, and there's one common class for all threads,
I (of course) need to syncrhonize access to it...
so, if I use AutoResetEvent, question is wich (and why) method I should use
to wait for "entrance" of a thread into a common class? ;)


is it WaitOne or WaitAll?
 
buu said:
If I have a multithreaded app, and there's one common class for all
threads, I (of course) need to syncrhonize access to it...
so, if I use AutoResetEvent, question is wich (and why) method I should
use to wait for "entrance" of a thread into a common class? ;)


is it WaitOne or WaitAll?

Use WaitOne. WaitAll is used when you have more than one Event to wait for.
 
I generally try to steer people away from AutoResetEvents in general. There
are a number of subtle behavior issues with them that tend to cause more
trouble than they're worth. There are certainly use cases where they're
perfect, but they're fairly few and far between.

If you're having to ask this as a question, you're best overall bet is
probably to switch away from an Event, and move to Monitor.

Between TryEnter / Pulse / PulseAll, you should be able to accomplish what
you need, and your code will end up being much more clear than that using an
Event.
 
Back
Top