Best way to clear a value from a ThreadLocal<T>

I am using a ThreadLocal<T> to store an item-per-thread, but every soft often, I wish to clear a thread's stored value. How is the best way of doing this? I can reset the instance's value to null, but the IsValueCreated property still shows true.


var storage = new ThreadLocal<string>();
storage.Value = "hello";
//storage.IsValueCreated -> true
storage.Value = null;
//storage.IsValueCreated -> still true


You can't de-initialize the data for a single thread. There is no method to do it (other than recreating the ThreadLocal<>, losing all the values)

Once assigned, the value of IsValueCreated is true for that thread. null is a perfectly ok value, it doesn't mean "deassign the value" or "the value is not assigned".

Need Your Help

Javascript print() method not working

javascript html css

I have a simple program that stores student objects in an array and then print the students info to the webpage. I have a print method in my program which takes a parameter and access the div eleme...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.