Is it safe to use CallContext.Logical [set / get] data when using .NET ThreadPool threads?

I understand that a LogicalCallContext that is set using these methods flows into new threads if you use ThreadPool.QueueUserWorkItem. The question is, when a thread that has this object is reused by the file pool, does the boolean call context reset? or am I ending up with a condition that does not belong to me?

A few references:

  • From what I can tell from the .net source code, the entire Execution context is cloned whenever you insert a new task into the thread pool. This context includes security-related stuff, so I would think that if the context is not reset, this will be a serious no-no.
  • In the test application, it seems to work fine even if I set the state from context to a dummy value after I ended up with it, just to make it more likely that I would have a bad state after reuse.
  • I do not use asynchronous programming, Windows / WPF forms or anything like that. Just regular calls to the .NET api (and none of them starts with "Get started ...")
  • I understand that just using Thread Local Storage, it just doesn't work, because it is NOT cleared when the thread switches.

thank

+4
source share
1 answer

I more or less simply answer what Hans answered.

, LCC - Remoting. , SecurityContext tp. CAS, .NET 4.0. .

, MS CallContext, Entity Framework 6, ( threasds , ).

, , .

0

All Articles