CLR Via C # reading notes---CLR homestay and application domains

Source: Internet
Author: User

#1 CLR Homestay :

When you develop the CLR, Microsoft actually implements it as a COM server that is contained in a single DLL . Microsoft has defined a standard COM interface for the CLR and assigned a GUIDto the interface and to the COM server. When you install the. NET Framework, the COM server that represents the CLR is registered in the Windows registry .

Any Windows application can host the CLR, and the unmanaged host should call the clrcreateinstance function declared in the MetaHost.h file, which is implemented in the MSCoreEE.dll file. The DLL is called a " shim " (shim) and is primarily used to determine which version of the CLR is created and does not itself contain a CLR COM server .

For the 1.0,1.1 and 2.0,clr codes in the MSCorWks.dll file, for version 4.0, the CLR code is in the Clr.dll file.

The clrcreateinstance function can return a iclrmetahost interface. The host application can call the getruntime function of this interface to specify the CLR version that is primarily created by the host. The shim then loads the required version of the CLR into the host program's process .

The getruntime function returns a pointer to the unmanaged interface ICLRRuntimeInfo , using the getinterface method of the interface to obtain the ICLRRuntimeHost interface.

With the release of the. NET Framework 4.0, Microsoft supports the simultaneous loading of CLR v2.0 and V4.0in a single Windows process, allowing different components written for the. NET Framework 2.0 and 4.0 to run concurrently. You can use the ClrVer.exe tool to check which version of the CLR is loaded in any given process.

After a CLR is loaded into a Windows process, it can never be uninstalled, and theonly way the CLR unloads from the process is to terminate the process , which causes the Windows cleanup process to use all the resources, including the CLR.

#2 AppDomain:

When the CLR COM server is initialized, an AppDomain is created. An AppDomain is a logical container for a set of assemblies. The first AppDomain created when CLR is initialized is called the default AppDomain, and this default AppDomain is destroyed only when the Windows process terminates.

The only role of the AppDomain is to isolate:

The code in one AppDomain creates objects that cannot be accessed directly by code in another AppDomain, and can only use the semantics of Marshal by reference or marshal by value.

The AppDomain can be uninstalled, protected separately, and can be configured separately.

CLR Via C # reading notes---CLR homestay and application domains

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.