I have a logging framework that I've written that has the ability to track "logging context". It has a pluggable strategy framework, however the one I use most often is a ThreadStatic variant that keeps track of context in a [ThreadStatic] variable.…
I want to figure out about singleton pattern designs. I want to create seperated instances for per thread from my singleton class. So I provided two designs below.
It is Working
class Program
{
static void Main(string[] args)
{
…
This is not a question of how to automatically call dispose - my problem is the opposite:
I have a thread pool where each thread has a ThreadStatic Graphics (which was created from an Image) to perform text size measuring. Now I've ran into the…
Is there a possibility to use thread static like variables within a single request? The current code uses a thread static variable for logging purposes and now we want to use async controller methods (with async and await pattern) which results in…
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…
I have a ThreadStatic member in a static class. The static class is used in a multi threaded environment. I want to make sure that when a thread is returned to threadpool (or re-used), the member is disposed (or re-initialized), so any subsequent…
[ThreadStatic] is used in various places in the .NET framework to provide an ambient context for various features (e.g. Transaction.Current, which is used for TransactionScope).
Unfortunately, this means that features which do some thread juggling…
I was refreshing my memory on C#'s ThreadStaticAttribute this morning, and the following line jumped out at me:
Use this attribute as it is, and do not derive from it.
This line is present in the docs for all versions of the .Net Framework, and…
I have this condition where I see that the thread's CallContext is carrying foreward the data in consequent calls.
Consider I have a simple API which when queired, will set one data entry into CallContext using :
// entry to the API execution…
I have just hit something weird when I was exploring Threads and Tasks using ThreadStatic Attribute. I believe this may be very specific to Threads and Tasks.
Consider the below code snippet:
[ThreadStatic]
static int range=10;
Action action =…
We have a fairly large existing code base for various webservices built on top of ASP.NET and that code makes heavy use of accessing HttpContext.Current.User (wrapped as Client.User) which I'm fairly sure internally uses [ThreadStatic] to give you…
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…
One of the libraries our WCF service references uses a ThreadStatic variable. The service method sets its value at the beginning of each call. I'm wondering if this is safe - in other words, can we guarantee that exactly one thread will be used…
I have a WCF service with ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple). I want to use ThreadStatic variable to srore data.
I start worrying about is it possible two parallel requests…
I'm using a variable with [ThreadStatic] attribute to store the current active Session for each socket (I'm using WebSocket as the connection type). In the beginning of socket connect, I assign its value with a new Session object, and then executing…