标签: c# multithreading thread-local
我见过的所有例子都会返回一个神奇的数字或一个字面上的字符串,它没什么用处。如果我想在ThreadLocal中存储非线程安全对象,这是正确的吗?
private ThreadLocal<Bar> threadLocal= new ThreadLocal<Bar>( () => new Bar() ); public void Foo() { Bar myBar = threadLocal.Value; }