Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Store data that is private to a thread using the thread object.

Store data that is private to a thread using the thread object.

Scheduled Pinned Locked Moved C#
helpsecurityquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bradsnobar
    wrote on last edited by
    #1

    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!!!

    T 1 Reply Last reply
    0
    • B bradsnobar

      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!!!

      T Offline
      T Offline
      TJoe
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • T TJoe

        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

        B Offline
        B Offline
        bradsnobar
        wrote on last edited by
        #3

        Thanks much. That seems to work. I was just confused about how SetData and GetData worked apparently.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups