CallContext logicalcallcontext Common variables under multi-threaded environments

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.