Monitor.Wait

  • Thread starter Thread starter John
  • Start date Start date
J

John

I use a profiler (DotTrace) and on my application it says that it is in
Monitor.Wait for 30% of the time.

What does it means exactly ? Is is a normal or not ?

Thanks
 
John,

The static Wait method is used to lock sections of code based on a
certain shared key (whatever is passed to Wait will act as the key that is
shared between threads to synchronize access to a section of code). While
your code might not call this (it will if you use the lock statement), the
base class library code most definitely will.

Hope this helps.
 
I actually explicitly use Monitor.Wait to block Threads.

The question is how does it affect performance.
 
John,

It depends completely on how you use it. Will it affect performance?
Yes, because it is going to have to perform an operation in order to
synchronize access. How much is really the key. If you have a gazillion
threads which require synchronization, then calls to lock have the potential
to take a very long time.

It's hard to tell without seeing your code and what you are doing.
Depending on what you are doing, 30% of your time in a call to Wait might be
reasonable (after all, the thread has to be blocked while waiting, and that
time spent blocking is included in this).
 
Back
Top