首页 新闻 会员 周边 捐助

ManualResetEvent .WaitOne(1000, false)这里的false或是true有什么区别?

0
[已解决问题] 解决于 2014-09-24 09:08

ManualResetEvent .WaitOne(1000, false)这里的false或是true有什么区别?什么叫离开同步领域?

baoj2010的主页 baoj2010 | 初学一级 | 园豆:102
提问于:2014-09-23 14:22
< >
分享
最佳答案
0

Notes on Exiting the Context

The exitContext parameter has no effect unless the WaitOne method is called from inside a nondefault managed context. This can happen if your thread is inside a call to an instance of a class derived from ContextBoundObject. Even if you are currently executing a method on a class that does not derive from ContextBoundObject, like String, you can be in a nondefault context if a ContextBoundObject is on your stack in the current application domain.

When your code is executing in a nondefault context, specifying true for exitContext causes the thread to exit the nondefault managed context (that is, to transition to the default context) before executing the WaitOne method. The thread returns to the original nondefault context after the call to the WaitOne method completes.

This can be useful when the context-bound class has SynchronizationAttribute. In that case, all calls to members of the class are automatically synchronized, and the synchronization domain is the entire body of code for the class. If code in the call stack of a member calls the WaitOne method and specifies true for exitContext, the thread exits the synchronization domain, allowing a thread that is blocked on a call to any member of the object to proceed. When the WaitOne method returns, the thread that made the call must wait to reenter the synchronization domain.

奖励园豆:5
Launcher | 高人七级 |园豆:45050 | 2014-09-23 14:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册