Is there a straightforward way to have a ThreadStatic instance member?

Posted by Dan Tao on Stack Overflow See other posts from Stack Overflow or by Dan Tao
Published on 2010-06-03T14:30:17Z Indexed on 2010/06/03 14:34 UTC
Read the original article Hit count: 169

With the ThreadStatic attribute I can have a static member of a class with one instance of the object per thread. This is really handy for achieving thread safety using types of objects that don't guarantee thread-safe instance methods (e.g., System.Random).

It only works for static members, though. Is there some corresponding attribute that provides the same functionality, but for instance members? In other words, that allows me to have one instance of the object, per thread, per instance of the containing class?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about multithreading