title: Thread Local Storage For C# Class Library
body: <p>I have a very old but very large library which I am considering converting to a C# class library. The existing library uses a lot of global variables stored in the TLS. C# has no real concept of global variables but one workaround is to use a static class called something like GlobalVar and put them all in this class so they can be accessed via GlobalVar.xxxxxx</p>
  
  <p>However, my thinking is that this will break all the existing code which is being converted as the GlobalVar class will be a normal global class and not per thread storage. Is there a way of getting these globals to be per thread? i.e. what is the equivalent of __declspec (thread) static in C#?</p>
  
  <p>I should add at this point that I hate global variables. I think they are often the result of poor design. However, due to tight time restrictions, phase one is to convert the library to C# with minimum fuss and then phase 2 will be to redesign them properly.</p>