2012-04-12 82 views

回答

1

我会建议一个静态(在这种情况下,appdomain静态)字典索引的线程ID与关联的getters和setter thtat索引到字典使用Thread.Current。

0

您可以使用LocalDataStoreSlot类,该类在Thread终止时自动丢弃该对象。

如:

private static readonly LocalDataStoreSlot nameSlot = Thread.AllocateDataSlot(); 

public string Name 
{ 
    get { return (string)Thread.GetData(nameSlot); } 
    set { Thread.SetData(nameSlot, value); } 
}