MyException - 我的异常网
当前位置:我的异常网» C# » Does C# support Thread Local

Does C# support Thread Local

www.MyException.Cn  网友分享于:2013-12-27  浏览:15次
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);

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有