[ThreadStatic()]是什么意思

我得到了一段代码,我发现了[ThreadStatic()]
在那里使用是什么意思。...何时使用[ThreadStatic()]

public class Context
{
[ThreadStatic()]
private static Context _Context = null;

private HttpContext _HttpContext = null;

public Context()
{
    _HttpContext = HttpContext.Current;
}

public static Context Current
{
    if(_Context == null ||
       _HttpContext != _HttpContext.Current)
    {
        _Context = new Context();
    }
    return _Context;
}
}

最佳答案

MSDN


  指示静态字段的值对于每个线程都是唯一的。


阅读以下内容:


A tale of two techniques: The [ThreadStatic] Attribute and System.Web.HttpContext.Current.Items
CallContext vs ThreadStatic
MSDN Blog: Are you familiar with [ThreadStatic]?
How well do you understand ThreadStatic?

关于c# - 关于[ThreadStatic()] C#,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7196229/

10-11 01:40