首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

Does C# support Thread Local

2011-12-26 
Does C# support Thread Local?Hi there,Is there some support in C# that support thread local variabl

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

热点排行