Can WaitHandle.WaitOne with ExitContext flag be used without ContextBoundObject class?

元气小坏坏 提交于 2019-12-13 00:57:12

问题


MSDN documentation suggests that there may be other ways of using ExitContext flag. See WaitHandle.WaitOne() What other ways are there to enter a non-default context outside of using a ContextBoundObject inherited class? (I can't use ContextBoundObject in my application)


回答1:


The clue is in this sentence.

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.

So basically you could call WaitOne from within a class that does not subclass ContextBoundObject nor would you have any preconceived notion that a ContextBoundObject was in any way involved with your code and yet the thread in question could be in a nondefault context because somewhere way up in the call stack an instance method of a ContextBoundObject class could be running unbeknown to you.

Outside of that lone exception there are no other ways of entering into a nondefault synchronization context.

There is a pretty good article on threading with additional information related to synchronization contexts which can be found here.



来源:https://stackoverflow.com/questions/3085861/can-waithandle-waitone-with-exitcontext-flag-be-used-without-contextboundobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!