简体   繁体   English

哪些方案构成.Net中的非默认执行上下文?

[英]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. WaitHandle.WaitOne()具有ExitContext选项,以允许在持有另一个资源之前临时释放资源锁。 This is useful in some cases where dead-lock or thread starvation may occur. 这在可能发生死锁或线程饥饿的某些情况下很有用。

The msdn documentaiton talks about a dondefault context. msdn文档讨论了dondefault上下文。 They only refer to examples which constitutes being in a nondefault context involving ContexBoundObject see ( Related Qusetion ). 它们仅引用构成非默认上下文中涉及ContexBoundObject的示例,请参见( Related Qusetion )。

Do other synchronization options such as Monitor.Enter(), Lock{} statements also constitute nondefault context? 其他同步选项(例如Monitor.Enter(),Lock {}语句)是否也构成非默认上下文? 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. 通过传递True,可以避免通信在解决等待之前阻塞,并允许分派其他消息。 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. WaitOne()的此参数引起了太多混乱和FUD,以至于.NET 2.0 SP1的兼容性发生了重大变化。 They added the WaitOne(int) and WaitOne(TimeSpan) overloads to avoid having to guess at the proper value of the exitContext argument. 他们添加了WaitOne(int)和WaitOne(TimeSpan)重载,以避免不得不猜测exitContext参数的正确值。 Which should normally be False. 通常应该是False。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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