WaitHandle and Monitor

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

Guest

Is there any way to find out:
1. which thread is holding a monitor object?
2. how many Monitor.Enter() has been called on an object?
3. which WaitHandle is signaled after WaitHandle.WaitAny()?

Thanks.
 
Hi,

See answers inline.
Is there any way to find out:
1. which thread is holding a monitor object?
Not as far as I know.
2. how many Monitor.Enter() has been called on an object?
No, if you want to use this to limit access to a resource you could
consider using a Semaphore.
Though .NET does not directly support Semaphore's they are easily
implemented. I have two implementations,
one that relies on the underlying OS Semaphore and a completely .NET
implementation. Each with there own
pros and cons. I will try to get them up asap and post a link.
3. which WaitHandle is signaled after WaitHandle.WaitAny()?
WaitAny returns an integer, this integer is the index of the handle in the
array that has been signalled

Hope this helps
 
Back
Top