. Net Framework Awareness

Source: Internet
Author: User

In the world of managed code, applications are loaded into the application domain (AppDomain) First, then the application domain is loaded into the process, and a process can contain multiple application domains, which means that a process can contain multiple applications, after all, switching between application domains is lighter than switching between processes.

Data between application domains is independent of each other, and you can use crossappdomaindelegate delegates when you need to execute assembly code in the current AppDomain in other AppDomain. After you delegate the Crocessappdomaindelegate method, the DoCallback method of the AppDomain executes the delegate.

classProgram {Static voidMain (string[] args) {Console.WriteLine ("The main program domain starts running"); //to create a new application domain objectAppDomain Newappdomain = Appdomain.createdomain ("Sub-Program fields"); //delegate method for binding CrossAppDomainDelegateCrossAppDomainDelegate crossappdomaindelegate =Newcrossappdomaindelegate (Mycallback); //the child application domain invokes the delegate, which is equivalent to the method in the subroutine domain calling the main program domainNewappdomain.docallback (crossappdomaindelegate); //Binding program Domain Unload event handling methodNewappdomain.domainunload + = (obj, e) = ={Console.WriteLine ("Sub-program domain uninstall!");            }; //To unload a sub-program domainappdomain.unload (Newappdomain);        Console.readkey (); }        Static  Public voidMycallback () {stringName =AppDomain.CurrentDomain.FriendlyName;  for(intn =0; N <4; n++) {Console.WriteLine (string. Format ("Current program runs on {0}", name)); }        }    }

A process can contain multiple threads, threads exist in the process, and it can run in many different AppDomain at different times. It is the basic unit of execution in the process, and the first thread that executes at the process entrance is considered the main path of the process. In. NET applications, the main () method is used as the portal, and when this method is called, the system automatically creates a main thread. Threads are primarily composed of CPU registers, call stacks, and thread local memory (TLS). The CPU registers primarily record the state of the currently executing thread, and the call stack is primarily used to maintain the memory and data that the thread invokes, and TLS is primarily used to hold the thread's state information.

. Net Framework Awareness

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.