DOTNET learning note three - programming area assembly

zhaozj2021-02-11  155

Most development technologies and environments define their own code execution and resources all. The operating system is in the range, IIS, ASP, and JSP are ranges from a virtual directory (Virtual Directory). The .NET's public language runtime (CLR) is based on application domain (AppDomain).

The programming domain basic and process is the same, which is the restricted area of ​​code running and resource access. The resources and address space of ordinary Win32 applications are shared in the process. All objects and resources in .NET can only be accessed in the range of AppDomain, and objects cannot be accessed in other appdomain. This way ensures the safety of the application, prevents intentional and unintentional code damage, can also prevent the crash of other Appdomain due to the crash of an appdomain. However, this premise is to ensure that the code is managed. If it is a non-managed code, such as using a pointer, theoretically access the memory space of the entire process, it may result in unpredictable things. Appdomain is less than the process. Each process operating system is assigned a kernel object to assign an address space. However, relative to each other is interviewed with each other (also using some special ways to implement, such as Windows Message, Memory Mapping, etc.), the interviews between AppDomain are difficult. However, Appdomain is a host of the process. A process can have multiple appdomain.

Using the AppDomain provided by .NET, we can create our own appdomain. As shown below:

Code 1 Namespace ConsoleApp

li

CATION1

{

///

/// summary description for class1.

///

Class class1

{

///

/// the main entry point for the app

li

CATION.

///

[Stathread]

Static void

Main

(String [] ARGS)

{

//

// Todo: Add code to start app

li

CATION Here

//

Console.writeline ("CurrentDomain Name IS: {0}", Appdomain.currentDomain.FriendlyName);

Appdomain newdomain = appdomain.createdomain ("new domain", null, null;

Newdomain.executeassemblyMbly ("ConsoleApp

li

CATION2.exe ");

}

}

}

Static variables using the AppDomain class CurrentDomain can get references to current Appdomain. Use a static function CreateDomain to create a new Appdomain. Executeassembly can perform an assembly. Two appdomain: currentdomain and newdomain in the above code are in the same process, this can be checked by the Windows Task Manager to see the number of processes, and the number of system processes only increases.

Assembly (Assembly) is similar to a normal program module, it can be one or more EXE and DLL files. Assembly has private and global points, private assebmly is just in the HOME directory of the program. Public Assembly must have a strong name and use the tools provided by .NET to install it into the system. Each appdomain has its own copy of Assembly, whether they are in the same process. As shown below:

This is not absolute, the user can determine if the CLR can determine whether APPDOMAIN within the process can share an assembly, which saves resources, increases speed, but at the same time.

Assembly is not uninstalled once loaded, unless its program domain is uninstalled. We can be programmed to uninstall Appdomain. In the code 1 Newdomain, we can use the APPDOMAIN.unload (NewDomain) to uninstall it.

转载请注明原文地址:https://www.9cbs.com/read-5803.html

New Post(0)