Questions tagged [threadstatic]

An attribute indicating that the value of a static field is unique for each thread.

An attribute indicating that the value of a static field is unique for each thread.

References

55 questions
2
votes
1 answer

Is there any way to imitate ThreadStatic for use with HttpContext.Current.Items?

Because of Thread Agility in ASP.Net, ThreadStatic is not an appropriate mechanism to use in web applications for segregating static property access from one request to the next. In order to avoid lots of calls to HttpContext.Current.Items and the…
Nathan Ridley
  • 33,766
  • 35
  • 123
  • 197
2
votes
4 answers

a viable solution to this problem?

I am calling from one piece of my code through several layers of 3rd party code, and the call surfaces back into my code at some point by calling some code I've written. In other words, the code call chain looks like this: My code #1 --> 3rd party…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
2
votes
1 answer

Why Initializing threadstatic attribute in Threadlocal delegate doesn't initilize it for the first thread?

I have created 3 threads and all threads have operation of increament on threadlocal attribute except thread1. I am also initializing threadstatic attribute in threadlocal delegate by the value of 11. Here I always get the value of num = 0 in the…
2
votes
3 answers

C# Thread Parameters change during thread execution - why?

So I have a method that gets a Dictionary of List, then cycles through the keys of the dictionary and passes each List to a separate thread. Here is some Code / Psuedo-Code: public static void ProcessEntries() { Dictionary
2
votes
1 answer

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.,…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
2
votes
1 answer

ThreadStatic field VS method parameter VS one instance per thread

Im working on a multithreaded application, therefore, I was always trying not to use private fields that may raise a conflict in the type instance i was using in different threads. Instead, I have been hauling information i needed to work as method…
Udontknow
  • 1,472
  • 12
  • 32
1
vote
2 answers

VB.NET 4.0: ThreadStatic doesn't appear to be thread safe for my TdConnection property

Here's my code: Dim _GlobalConnection As TdConnection Public Property GlobalConnection As TdConnection Get If _GlobalConnection Is Nothing Then _GlobalConnection = New TdConnection End If If…
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
1
vote
1 answer

.NET 4.0: How to clean up object references attributed as threadstatic after the thread as since exectured?

I have a static connection variable in an ASP.NET webform codebehind. In the page load event, I am executing several methods in separate threads. Each thread utilizes a threadstatic instance of this connection object. What I want to do is, in the…
oscilatingcretin
  • 10,457
  • 39
  • 119
  • 206
1
vote
0 answers

.NET: Does ExecutionContext.SuppressFlow dissociate ThreadStatic variables?

The title of the question pretty much says it all. Will static variables marked with the [ThreadStaticAttribute] get messed up if you use ExecutionContext.SuppressFlow() to cancel the propagation of the security context and identity token, etc.? In…
Glenn Slayden
  • 17,543
  • 3
  • 114
  • 108
1
vote
1 answer

CRM 2011 OrganizationService Disposed

We're creating an ASP.NET MVC app that talks to CRM 2011. We are using the Xrm.Client.Services.OrganizationService. We have a singleton pattern in place for this. Under load we are seeing an ObjectDisposedException (cannot access a disposed…
1
vote
2 answers

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…
Daniel
  • 47,404
  • 11
  • 101
  • 179
1
vote
1 answer

Access ThreadStatic - Variable from outside of the thread

I have defined a Variable as ThreadStatic: public static class MyApplicationContext { [ThreadStatic] public static bool Monitoring; } Now, I should set the variable Monitoring from the MainThread (which have started the new…
BennoDual
  • 5,865
  • 15
  • 67
  • 153
1
vote
1 answer

Strange 'Index was out of range' (Multithreading issue)

I'm writing a Windows service in C# (Visual Studio 2013). The service activates a thread for each server it connects with. The 'server' object is defined as 'ThreadStatic' (so each thread should access it as a different…
1
vote
3 answers

ThreadStatic and ASP.NET

I've got a requirement to protect my business object properties via a list of separate authorization rules. I want my authorization rules to be suspended during various operations such as converting to DTOs and executing validation rules (validating…
agartee
  • 445
  • 2
  • 15
1
vote
0 answers

is thread switching possible during request processing?

I have an MVC application, which also uses EF and a simple Unit of work pattern implementation. Here's what my UnitOfWork looks like: public class UnitOfWork : IUnitOfWork { [ThreadStatic] private static UnitOfWork _current; private…
nativehr
  • 1,131
  • 6
  • 16