Why is ThreadStatic data being unexpectedly shared between threads? Why is ThreadStatic data being unexpectedly shared between threads? multithreading multithreading

Why is ThreadStatic data being unexpectedly shared between threads?


Because that field isn't static. It only applies to static fields.

If this is 4.0, maybe look at ThreadLocal<T>


As @MarcGravell points out your field is not static, which is the cause of your problem.

However, if a consumer were to store the return from GetLoggingContext this value would be available to be shared between threads. I generally try to use any ThreadStatic variables as implementation details of a class, rather than exposing them outside of it.