Does C# support Thread Local?

ShaoKao 2008-03-21 03:24:09
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
...全文
98 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
guoyichao 2008-03-21
  • 打赏
  • 举报
回复
.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);

110,546

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧