title: Deterministic dispose of ThreadStatic objects
body: <p>The <a href="https://stackoverflow.com/questions/9033?#13932">ThreadStatic attribute</a> declares a static variable as unique-per-thread.
  Do you know an easy pattern to correctly dispose such variables?</p>
  <p>What we used before ThreadStatic is a ThreadContextManager. Every thread was allocated a ThreadContext which retained all thread-specific information. We spawned some threads and let them work. Then, when they all finished, we disposed of the ThreadContentManager, which in turn disposed all the contexts if they were IDisposable.</p>
  <p>I don't see an immediate way to translate this pattern to ThreadStatic objects. The objects will be disposed of eventualy, because the threads die, and so nothing reference them. However, we prefer deterministic dispose whenever possible.</p>
  <p><strong>Update</strong></p>
  <p>I do not really control the threads directly - I'm using Microsoft CCR, which has a ThreadPool that does tasks. When all the tasks are done, I'm disposing the Dispatcher (which holds the threadpool). The thing is - I do not get a chance to do anything &quot;at the end of a thread's main function&quot; - so I can't dispose things manually at the end of a thread's run. Can I access the thread's static objects from outside the thread somehow?</p>