views:

49

answers:

2

Is there a possibility in .NET to bind an object instance to a current execution context of a thread? So that in any part of the code I could do something like CurrentThread.MyObjectData.DoOperation() and be sure that I access thread-specific data? thanks!

+4  A: 

You could take a look at the ThreadStaticAttribute. Another helpful methods are SetData/GetData which allow you to store data relative to the current thread.

Darin Dimitrov
fantastic! that's what I need!
Andy
+1  A: 

If you're using .NET 4.0, there's now also ThreadLocal<T>:

System.Threading.ThreadLocal<T>

Nick

Nick Butler