Difference between Monitor.Enter/Monitor.Wait and AutoResetEvent.W

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Could some one please explain to me what the different between Monitor.Enter
and Monitor.Wait is? Does the Monitor.Wait result in the thread entering a
WaitSleepJoin state and not using any CPU cycles (signalled by Pulse) unlike
Monitor.Enter which keeps attempting to acquire the lock? In addition, how
does this differ to AutoResetEvent.Wait.

Thanks in advance for any help.
 
Monitor.Enter acquires the lock on the object, no other thread can access
the object

Monitor.Wait
[When a thread calls Wait, it releases the lock on the object and enters the
object's waiting queue.
The thread that currently owns the lock on the specified object invokes this
method in order to release the object so that another thread can access it.
The caller is blocked while waiting to reacquire the lock. This method is
called when the caller is waiting for a change in the state of the object
that will occur as a result of another thread's operations on the object.]

AutoResetEvent is used for thread communication via signals. Flavor of
AutoResetEvent is that you have not to call Reset.
 
Back
Top