开发者

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{} stat开发者_StackOverflow中文版ements 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜