Let's begin by understanding the following basic concepts before starting this section.
application domain
application domains, often referred to as AppDomain, can be considered as a lightweight process. You can include multiple appdomain within a Windows process. The concept of AppDomain is proposed to enable multiple applications to be hosted on a single physical server, and these applications can be independent of each other. Asp. NET is an example of using AppDomain to host multiple Web applications within the same process. In fact, Microsoft has had a stress test that hosts up to 1000 simple Web applications in a single process.
The performance advantages obtained by using AppDomain are mainly embodied in two aspects:
• Less system resources are needed to create a AppDomain than to create a Windows process.
• Sharing resources between AppDomain hosted within the same Windows process, such as the CLR, Basic. NET type, address space, and threads.
The independence of each AppDomain is embodied in the following characteristics:
• A appdomain can be unloaded independently of other AppDomain.
• One AppDomain cannot access other AppDomain assemblies and objects.
• If no cross boundary exception is thrown, a AppDomain has its own independent exception management strategy. This means that a problem within a AppDomain does not affect other AppDomain in the same process.
• Each AppDomain can define a separate assembly code access security policy.
• Each AppDomain can define separate rules so that the CLR locates the assembly location before loading.
You can see that the application domain is a child unit in the process, but in the. NET also has a finer-grained unit than the application domain ——. NET contexts (context).
. NET Context
A. NET application domain can contain more than one called. NET context. All. NET objects exist in the context, and there is at least one context in each application domain. This context is called the default context for the application domain, which is created when the application domain is created. The following diagram summarizes the relationships between them: