开发者

What is the use case for System.Threading.CompressedStack

I'm trying to find a practical use for Syst开发者_如何学编程em.Threading.CompressedStack. Something cool, not "Oh, we can move the stack from one thread to another for fun", but rather when one would actually want to do that or whatever else you can do with this fun little class.


Straight from the documentation:

"This class is not used in ordinary application programming."

I guess it is only for extraordinary application programming.


This is really designed for internal use by the framework. From the documentation:

The CompressedStack class is used internally by the SecurityContext class. For example, the SecurityContext.Capture method captures the compressed stack for the current call stack, along with impersonation and culture information. The SecurityContext class is used in turn by the ExecutionContext class to flow context across threads, for example when scheduling thread pool tasks.

This class is not used in ordinary application programming.


It's an extremely useful class when creating plugins and sandboxes. One can capture CAS context of the host (CompressedStack.Capture) and then when plugin calls back trusted host method (CompressedStack.Run) allows to "resume execution" under host execution context.

Otherwise "trusted" host method would execute as untrusted code and will run into multiple SecurityExceptions when trying to access CAS protected resources.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜