.NET technology FAQ (4) ----- Application domain

xiaoxiao2021-03-06  59

4. Application Domain 4.1 What is the application domain? AppDomain can be seen as a lightweight process. There can be multiple Appdomain in a Win32 process. The main purpose of AppDomain is to separate applications and other applications. By using a separate address space, the Win32 process provides isolation. This method is effective, but the overhead is very large and the telescopic is not good. The .NET runtime is managed by controlling memory by controlling all memory used to apply AppDomain isolation -AppDomain, so the run library ensures that the APPDOMAIN cannot access each other's memory. 4.2 How to create AppDomain? Appdomains usually have host creation. The host includes Windows Shell, ASP and IE. When you run a .NET application from the command line, the host is the shell. Shell Creates a new AppDomain for each app. AppDomains can also be explicitly created by .NET applications. Here is a C # example of creating Appdomain, which creates an instance of an object, and then performs a method of the object: use system; use system.Runtime.Remoting;

Public class cappdomaininfo: MarshalByrefObject {public string getAppdomainInfo () {return "Appdomain =" Appdomain.currentDomain.FriendlyName;}

}

public class App {public static int Main () {AppDomain ad = AppDomain.CreateDomain ( "Andy's new domain", null, null); ObjectHandle oh = ad.CreateInstance ( "appdomaintest.exe", "CAppDomainInfo"); CAppDomainInfo adInfo = (Oh.unwrap ()); string info = adinfo.getAppdomainInfo (); console.writeline ("Appdomain Info:" info); return 0;}}

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

New Post(0)