.net – When would I use AutoResetEvent and ManualResetEvent instead of Monitor.Wait()/Monitor.Pulse()

lockingmultithreadingnetsynchronization

They both seem to fulfill the same purpose. When would I chose one over the other?

Best Answer

Use the events when you've got a thread that is waiting on one of or all of a number of events to do something.

Use the monitor if you want to restrict access to a data structure by limiting how many threads can access it.

Monitors usually protect a resource, whereas events tell you something's happening, like the application shutting down.

Also, events can be named (see the OpenExisting method), this allows them to be used for synchronization across different processes.