简体   繁体   中英

What scenarios constitute a Non-Default Execution Context in .Net?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM