简体   繁体   English

将环境数据添加到线程

[英]Adding ambient data to the thread

I want to add custom data to the thread. 我想将自定义数据添加到线程中。 For example, ambient transaction scope are stored in the thread as well as identity info. 例如,环境事务范围和身份信息都存储在线程中。 I would like to have my own ambient data available. 我想拥有自己的环境数据。 Is there a way to do this OTB or would there be a lot of work that just isnt worth it? 有没有办法做这种OTB,还是会有很多工作不值得?

Let's say that I have a using 假设我有一个使用

using(var x = new MyDataClass())
{
 SomeMethod();
}

In SomeMethod() I want to have access to the instance of MyDataClass that was declared in the calling method. SomeMethod()我想访问在调用方法中声明的MyDataClass实例。

Sounds like you are looking for ThreadStaticAttribute , unless I completely misunderstood the question. 听起来您正在寻找ThreadStaticAttribute ,除非我完全误解了这个问题。

This article - Thread Local Storage: Thread-Relative Static Fields and Data Slots , may be of interest. 本文- 线程本地存储:相对于线程的静态字段和数据插槽 ,可能是您感兴趣的内容。

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

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