You've heard of this class. Here: How to achieve unified management of context data
Originally thought that callcontext can be directly in the multi-threaded environment under the shared use, today suddenly thought: the ASP. NET environment below, set to set to go, the object is not to be confused by multiple clients?
The following code tests are done:
static void Main (string[] args) { callcontext.logicalsetdata ("Key", "1"); Thread TRD = new Thread (new ThreadStart () = { Console.WriteLine ("First thread:" + CALLCONTEXT.LOGICALGETDA TA ("key")); Thread.Sleep (+); Console.WriteLine ("First thread:" + callcontext.logicalgetdata ("key"));) ; Trd. Start (); Thread.Sleep (+); Callcontext.logicalsetdata ("Key", "2"); Thread trd1 = new Thread (new ThreadStart () = { Console.WriteLine ("Second thread:" + callcontext.logicalg Etdata ("key" )); Trd1. Start (); Console.read (); }
The result is the bird's appearance:
It seems that I think a lot of Ah, Khan ...
Excerpt from an official note (from the blog of the Artech Great God):
LogicalCallContext: The LogicalCallContext class is a version of the CallContext class that is used when making method calls to a remote application domain. CallContext is a dedicated collection object that resembles a thread-local store of method calls and provides a data slot that is unique to each logical execution thread. Data slots are not shared between call contexts on other logical threads. You can add an object to the CallContext when it is propagated round-trip along the execution code path and is checked by individual objects in that path. When a remote method call is made to an object in another AppDomain , the CallContext class generates a logicalcallcontext that propagates with the remote call. only objects that expose the ILogicalThreadAffinative interface and are stored in CallContext are propagated outside the AppDomain in LogicalCallContext. Objects that do not support this interface are not transferred with the remote method call in the LogicalCallContext instance.
the CallContext class will generate a logicalcallcontext that propagates with the remote call. "
It should be said to pass the past, regardless of the citation relationship, like "value pass" it.
Welcome to the Great God treatise ...
CallContext logicalcallcontext Common variables under multi-threaded environments