读书人

Does C# support Thread Local

发布时间: 2011-12-26 23:09:58 作者: rapoo

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);

读书人网 >C#

热点推荐