views:

28

answers:

1

WaitHandle.WaitOne() has an ExitContext option to allow for temporary release of a resource lock before holding for another. This is useful in some cases where dead-lock or thread starvation may occur.

The msdn documentaiton talks about a dondefault context. They only refer to examples which constitutes being in a nondefault context involving ContexBoundObject see (Related Qusetion).

Do other synchronization options such as Monitor.Enter(), Lock{} statements also constitute nondefault context? What other scenarios would place a thread execution in nondefault context?

+1  A: 

It is a tricky subject and I don't know enough about it. What I do know is that it is relevant in Remoting scenarios. By passing True, you can avoid communication from blocking until the wait is resolved and allow other messages to be dispatched. Yes, avoids deadlock but can cause synchronization problems.

This argument to WaitOne() has caused so much confusion and FUD that .NET 2.0 SP1 had a compatibility breaking change. They added the WaitOne(int) and WaitOne(TimeSpan) overloads to avoid having to guess at the proper value of the exitContext argument. Which should normally be False.

Hans Passant