日期:2014-05-18  浏览次数:20929 次

Does C# support Thread Local?
Hi there, 

Is there some support in C# that support thread local variables like that in Java? Thank you.

BTW, I have no Chs input method installed on my work station. Sorry.

Rgds,
ShaoKao

------解决方案--------------------
.net支持2种TLS,static field和data slots

static filed:
[ThreadStatic]
int i;

data slots(unnamed):
LocalDataStoreSlot slot=Thread.AllocateDataSlot();
Thread.SetData(slot, i);
i=Thread.GetData(slot);