threadstatic

Can I (safely) use the ThreadStatic attribute in ADO.NET Data Services?

I want to store per-thread data in an ADO.NET Data Service. Is it safe to use the ThreadStatic attribute on my thread-specific static variable, or will I run into problems? My concern is that my ThreadStatic variable(s) won't be garbage collected after the request is completed and the thread dies. If there's a better way to do what I'm...

BizTalk mapper and the [ThreadStatic] attribute

I've recently encountered an issue with the multi-threaded nature of the BizTalk Mapper and how it handles external assemblies. As this quote from MSDN indicates: Important Any code written in an external assembly for use in a scripting functoid needs to be thread safe. This is required because multiple instances of a map c...

Inheriting ThreadStatic values to implement dynamic scoping in C#/.NET in multithreaded context

Is there a way to make newly-spawned threads inherit the values of ThreadStatic state (or something like it) on their parent threads? I would like to use this (or something like it) to implement "dynamically scoped" special variables that contain operation/task context information to use for tracking/logging, etc. Is this a reasonable ...

Are WCF request handling Thread Agile?

I have seen lots of documentation on how Agile Asp.Net Request handling is? I want to know is the case same with WCF Request handling. Can we rely on the fact that the Thread that starts Wcf request handling will finish it? I am maintaining a Wcf Application where at lots of places ThreadStatic variables are used. Although the code is w...

Is something along the lines of nested memoization needed here?

System.Transactions notoriously escalates transactions involving multiple connections to the same database to the DTC. The module and helper class, ConnectionContext, below are meant to prevent this by ensuring multiple connection requests for the same database return the same connection object. This is, in some sense, memoization, altho...

Is there a straightforward way to have a thread-local instance variable?

With the ThreadStatic attribute I can have a static member of a class with one instance of the object per thread. This is really handy for achieving thread safety using types of objects that don't guarantee thread-safe instance methods (e.g., System.Random). It only works for static members, though. Is there any straightforward way to d...

C# Thread Parameters change during thread execution - why?

So I have a method that gets a Dictionary of List<myObj>, then cycles through the keys of the dictionary and passes each List<myObj> to a separate thread. Here is some Code / Psuedo-Code: public static void ProcessEntries() { Dictionary<string, List<myObj>> myDictionary = GetDictionary(); foreach(string key in myDictionary.ke...

ThreadStatic member lose value on every page load

I have veeeeryyy basic singleton in asp.net web application: [ThreadStatic] private static BackgroundProcessManager2 _Instance; public static BackgroundProcessManager2 Instance { get { if (_Instance == null) // ** { _Instance = new BackgroundProcessManager2(); } return _...

ThreadStatic vs. ThreadLocal<T> Performance

I recently read this post about poor performance of fields marked ThreadStatic - they're apparently 60x slower than normal field access. Does .NET 4's ThreadLocal< T > perform any better? Are there any alternatives that offer high performance thread-specific storage? ...