On the. NET platform, the Assembly is not directly hosted in the process (whereas the traditional win32 program is directly hosted ). In fact,. NET executable programs are carried in a logical partition of the process. The term is called an application domain (also called AppDomain ). It can be seen that a process can contain multiple application domains, and each application domain carries one. NET executable program. The benefits are as follows:
The application domain is a key feature of the operating system independence of the. NET platform. This logical partition abstracts the differences between different operating systems for loading executable programs.
Compared with a complete process, the CPU and memory usage of the application domain is much smaller. Therefore, CLR loads and detaches application domains much faster than the complete process.
Application domains provide deep isolation for hosted applications. If one application domain in the process fails, other application domains will remain normal.
Main AppDomain members:
CreateDomain (): This static method creates a new application domain in the current process. Since CLR can create application domains as needed, there are few opportunities to call this method.
GetCurrentThreadId (): The static method returns the ID of the active thread in the current application domain.
UnLoad (): This static method detaches the specified application domain in the process.
BaseDirectory: gets the base Directory, which is used to detect the relevant Assembly.
CreateInstance (): Create a new instance of the specified type in the specified Assembly file.
ExecuteAssembly (): executes an assembly in the application domain based on the file name.
GetAssemblies (): gets the. NET assembly that has been loaded into this application domain (except for binary files based on COM and C ).
Load (): dynamically Load the assembly to the current application domain.