Store data that is private to a thread using the thread object.
-
Hello, How do I save data to the current thread. I want it to be accessible only to the current thread. I need to be able to store data specific to a thread without being able to have control over the object that a thread is executing on. This is because most of the control is handed off to the runtime, so I can't just add it to an object that is created and used to launch my own thread. I've found a method that looks promising: System.Threading.Thread.SetData System.Threading.Thread.GetData The problem is that it takes a slot as a parameter and I won't be able to use the same slot name across all the calls to set and get data or the data will just get overwritten by other threads. I want to store authentication information here. So, it needs to be unique for each thread. (In case you are wondering... I can't use the CurrentPrinicple object for my auth.) Also, the data can be shared across all of the threads with the slots and that is also bad because authentication information shouldn't be shared like that. Any ideas will be a great help. Thanks!!!
-
Hello, How do I save data to the current thread. I want it to be accessible only to the current thread. I need to be able to store data specific to a thread without being able to have control over the object that a thread is executing on. This is because most of the control is handed off to the runtime, so I can't just add it to an object that is created and used to launch my own thread. I've found a method that looks promising: System.Threading.Thread.SetData System.Threading.Thread.GetData The problem is that it takes a slot as a parameter and I won't be able to use the same slot name across all the calls to set and get data or the data will just get overwritten by other threads. I want to store authentication information here. So, it needs to be unique for each thread. (In case you are wondering... I can't use the CurrentPrinicple object for my auth.) Also, the data can be shared across all of the threads with the slots and that is also bad because authentication information shouldn't be shared like that. Any ideas will be a great help. Thanks!!!
bradsnobar wrote:
The problem is that it takes a slot as a parameter and I won't be able to use the same slot name across all the calls to set and get data or the data will just get overwritten by other threads.
When you use GetData and SetData, then slot is thread specific. So if I store data on ThreadA to a slot (say "MySlot"), then ThreadB can store different data to a slot by the same name. ThreadB cannot overwrite the data stored by ThreadA.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
-
bradsnobar wrote:
The problem is that it takes a slot as a parameter and I won't be able to use the same slot name across all the calls to set and get data or the data will just get overwritten by other threads.
When you use GetData and SetData, then slot is thread specific. So if I store data on ThreadA to a slot (say "MySlot"), then ThreadB can store different data to a slot by the same name. ThreadB cannot overwrite the data stored by ThreadA.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
Thanks much. That seems to work. I was just confused about how SetData and GetData worked apparently.