开发者

Thread-exclusive data: how to store and access?

开发者 https://www.devze.com 2022-12-21 07:30 出处:网络
Is there a possibility in .NET to bind an object instance to a current execution context of a thread?

Is there a possibility in .NET to bind an object instance to a current execution context of a thread? So that in any开发者_高级运维 part of the code I could do something like CurrentThread.MyObjectData.DoOperation() and be sure that I access thread-specific data? thanks!


You could take a look at the ThreadStaticAttribute. Another helpful methods are SetData/GetData which allow you to store data relative to the current thread.


If you're using .NET 4.0, there's now also ThreadLocal<T>:

System.Threading.ThreadLocal<T>

Nick

0

精彩评论

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