System.AppDomain class

Source: Internet
Author: User

Processes are independent of memory and resources, but the AppDomain is only a logical abstraction. A process can exist in more than one AppDomain. Data between the AppDomain is independent of each other. A thread can shuttle multiple AppDomain.

First, the attribute

ActivationContext gets the activation context for the current application domain.
ApplicationIdentity gets the application identity in the application domain.
ApplicationTrust Gets the information that describes the permissions granted to the application and whether the application has a trust level that allows it to run.
BaseDirectory gets the base directory, which is used by the Assembly resolver to probe assemblies.
CurrentDomain gets the current application domain of the Thread.
Domainmanager Gets the domain manager provided by the host when the application domain is initialized.
Dynamicdirectory Gets the directory that is used by the Assembly resolver to probe for dynamically created assemblies.
Evidence gets the Evidence associated with the application domain.
FriendlyName gets the friendly name of this application domain.
Id gets an integer that uniquely identifies the application domain in the process.
IsFullyTrusted gets a value that indicates whether the assembly that is loaded into the current application domain is executed in full trust.
Ishomogenous gets a value that indicates whether the current application domain has a permission set granted to all assemblies loaded into the application domain.
Monitoringisenabled Gets or sets a value that indicates whether CPU and memory monitoring of the application domain is enabled for the current process. Once monitoring is enabled for a process, it cannot be disabled.
Monitoringsurvivedmemorysize Gets the number of bytes that are known to be referenced by the current application domain after the last fully blocked collection.
Monitoringsurvivedprocessmemorysize gets the total number of bytes that were retained after the last full block collection of all application domains in the process.
Monitoringtotalallocatedmemorysize gets the total size, in bytes, of all memory allocations that have been made by the application domain since the application domain was created, without deducting the reclaimed memory.
Monitoringtotalprocessortime gets the total processor time that is used by threads that have been executing in the current application domain since the process started.
PermissionSet gets the permission set for the sandbox application domain.
Relativesearchpath gets the path under the base directory in which the Assembly resolver should probe the private assembly.
Setupinformation Gets the application domain configuration information for this instance.
Shadowcopyfiles gets an indication whether the application domain is configured as an image copy file.

 Public classProgram {Static voidMain (string[] args) {AppDomain AppDomain= Appdomain.currentdomain;//gets the current application domain of the Thread. Console.WriteLine (AppDomain. ID);//Output 1 Gets an integer that uniquely identifies the application domain in the process. Console.WriteLine (AppDomain. ActivationContext);//output whitespace Gets the activation context for the current application domain. Console.WriteLine (AppDomain. applicationidentity);//output whitespace gets the application identity in the application domain. ApplicationTrust at= AppDomain. ApplicationTrust;//Gets the information that describes the permissions granted to the application and whether the application has a trust level that allows it to run. Console.WriteLine (AppDomain. ApplicationTrust);//Output System.Security.Policy.ApplicationTrustConsole.WriteLine (AppDomain.         BaseDirectory); //the output F:\xxx\xxx\ConsoleApplication1\bin\Debug\ gets the base directory, which is used by the Assembly resolver to probe assemblies. AppDomainManager ADM= AppDomain. Domainmanager;//Gets the domain manager provided by the host when the application domain is initialized. Console.WriteLine (Adm.EntryAssembly.Location);//Output F:\xxx\xxx\ConsoleApplication1\bin\Debug\ConsoleApplication1.exeConsole.WriteLine (AppDomain. Domainmanager);//Output Microsoft.VisualStudio.HostingProcess.VSHostAppDomainManagerConsole.WriteLine (AppDomain.      Dynamicdirectory); //output whitespace Gets the directory, which is used by the Assembly resolver to probe for dynamically created assemblies. Evidence Ed= AppDomain. Evidence;//another thing. Gets the Evidence associated with the application domain. Console.WriteLine (AppDomain. Evidence.tostring ());//Output System.Security.Policy.EvidenceConsole.WriteLine (AppDomain.          FriendlyName); //output ConsoleApplication1.vshost.exe Gets the friendly name of this application domain. Console.WriteLine (AppDomain.        isfullytrusted); //output True Gets a value that indicates whether the assembly that is loaded into the current application domain is executed in full trust. Console.WriteLine (AppDomain.          ishomogenous); //output True Gets a value that indicates whether the current application domain has a permission set granted to all assemblies loaded into the application domain. Console.WriteLine (appdomain.monitoringisenabled); //output False Gets or sets a value that indicates whether the application domain's CPU and memory monitoring is enabled for the current process. Once monitoring is enabled for a process, it cannot be disabled. appdomain.monitoringisenabled=true; //This property can be used when the above property is enabledConsole.WriteLine (AppDomain. Monitoringsurvivedmemorysize);//output 0 Gets the number of bytes that are known to be referenced by the current application domain after the last fully blocked collection. Console.WriteLine (AppDomain. Monitoringtotalallocatedmemorysize);//output 0 Gets the total size, in bytes, of all memory allocations that have been made by the application domain since the application domain was created, without deducting the reclaimed memory. Console.WriteLine (AppDomain. Monitoringtotalprocessortime);//output 00:00:00 Gets the total processor time that is used by threads that have been executing in the current application domain since the process started. System.Security.PermissionSet PS= AppDomain. PermissionSet;//gets the permission set for the sandbox application domain. Console.WriteLine (AppDomain.      Permissionset.tostring ()); //output <permissionset class= "System.Security.PermissionSet" version= "1" unrestricted= "true"/>Console.WriteLine (AppDomain.    Relativesearchpath); //Output BlankConsole.WriteLine (AppDomain.      Setupinformation); //output AppDomainSetup Gets the application domain configuration information for this instance. Console.WriteLine (AppDomain.       Shadowcopyfiles); //Output FalseFile.writealltext (@"D:\123.txt", AppDomain.               Permissionset.tostring ()); //setupinformation Gets the application domain configuration information for this instance. //Shadowcopyfiles Gets an indication whether the application domain is configured as an image copy file. Console.readkey (); Copy the Code
View Code

Second, the method

Name Description
ApplyPolicy returns the assembly display name after the policy is applied.
Createcominstancefrom (String, String) creates a new instance of the specified COM type. parameter specifies the name of the file that contains the assembly that contains the type and type name.
CreateDomain (String) creates a new application domain with the specified name.
CreateInstance (String, String) creates a new instance of the specified type defined in the specified assembly.
Createinstanceandunwrap (String, String) creates a new instance of the specified type. Formal parameters specify the assembly that defines the type and the name of the type.
CreateInstanceFrom (String, String) creates a new instance of the specified type defined in the specified assembly file.
Createobjref creates an object that contains all the relevant information that is required to generate a proxy for communicating with a remote object. (inherited from MarshalByRefObject.) )
DefineDynamicAssembly (AssemblyName, assemblybuilderaccess) defines the dynamic assembly with the specified name and access pattern.
DoCallback executes code in another application domain that is identified by the specified delegate.
ExecuteAssembly (String) executes the assembly contained in the specified file.
ExecuteAssemblyByName (String) executes the assembly given its display name.
Getassemblies Gets the assembly that has been loaded into the execution context of this application domain.
GetData gets the value stored in the current application domain for the specified name.
Getlifetimeservice retrieves the current lifetime service object that controls the lifetime policy of this instance. (inherited from MarshalByRefObject.) )
InitializeLifetimeService gives the AppDomain an infinite lifetime by preventing the creation of leases. (Rewrite MarshalByRefObject.InitializeLifetimeService (). )
Iscompatibilityswitchset gets a nullable Boolean value that indicates whether any compatibility switch is set, or whether the specified compatibility switch is set if it is set.
Isdefaultappdomain returns a value that indicates whether the application domain is the default application domain for the process.
Isfinalizingforunload Indicates whether this application domain is unloading and whether the common language runtime is terminating the objects that the domain contains.
Load (assemblyname) loads the Assembly in the case of a given AssemblyName.
Reflectiononlygetassemblies returns an assembly that has been loaded into the reflection-only context of the application domain.
SetData (String, Object) assigns the specified value to the specified application domain property.
SetData (String, Object, IPermission) assigns the specified value to the specified application domain property, which requires the caller to have the specified permission when retrieving the property.
SETPRINCIPALPOLICY specifies how the user and identity object should be attached to the thread when it executes in this application domain if the thread tries to bind to the user.
SetThreadPrincipal sets the default principal object to be attached to the thread when the thread is executing in this application domain, if the thread tries to bind to the principal in this case.
Unload Uninstalls the specified application domain.

classProgram {Static voidMain (string[] args) {AppDomain app= Appdomain.createdomain ("test program Domain");//to create an application domain with the specified nameObjectHandle Objhan = App. CreateInstance ("MySpace","Myspace.person");//creates the specified object in the specified assembly            varobj =Objhan.unwrap (); Console.WriteLine (obj.  ToString ()); //Output Myspace.person            ObjectObj2 = App. Createinstanceandunwrap ("MySpace","Myspace.person");//creates the specified object in the specified program, incidentally executing the Unwrap methodConsole.WriteLine (Obj2. ToString ());//Output Myspace.personObjectHandle objHan2= App. CreateInstanceFrom (@"D:\MySpace.dll","Myspace.person");//To create an object of a class from a specified assembly            ObjectObj3 =Objhan2.unwrap (); Console.WriteLine (obj3. ToString ()); //Output Myspace.person//app. Createobjref ();app. ExecuteAssembly (@"D:\ConsoleApplication1.exe");//executes the assembly output contained in the specified file 0123456789//the code for D:\ConsoleApplication1.exe is as follows//static void Main (string[] args)//{            //for (int i = 0; i <; i++)//    {            //Console.WriteLine (i); //    }            //Console.readkey (); //}            //change D:\ConsoleApplication1.exe below, instead create a file under D and write a textApp. ExecuteAssembly (@"D:\ConsoleApplication1.exe");//after running, a file is created under the D disk, and the text is written//static void Main (string[] args)//{            //File.writealltext (@ "D:\AppDomainTest.txt", "Test test"); //Console.readkey (); //}            //Note that this time because of the console.readkey (), so the execution here to press two times the keyboard, so that the app domain executes before returning to the main program domainassembly[] Assarr = App. Getassemblies ();//get all assemblies loaded into the app application domain                        foreach(varTheinchAssarr) {Console.WriteLine (the.    FullName); //Such ConsoleApplication1, version=1.0.0.0, culture=neutral, Publickeytoken=null            }            //mount an assembly given assemblyApp. Load ("MySpace"); Console.WriteLine (App.  Isdefaultappdomain ()); //output False Whether the process is the default application domainapp. SetData ("data1","Holy crap");//assigns the specified value to the specified application domain property.             Objecto = App. GetData ("data1");    Console.WriteLine (O.tostring ()); //Output I//ApplyPolicy Returns the assembly display name after the policy is applied. //Createcominstancefrom (String, String) creates a new instance of the specified COM type.            parameter specifies the name of the file that contains the assembly that contains the type and type name. //Createobjref creates an object that contains all the relevant information that is required to generate a proxy for communicating with a remote object. (inherited from MarshalByRefObject.) )//definedynamicassembly (AssemblyName, assemblybuilderaccess) defines the dynamic assembly with the specified name and access pattern. //DoCallback executes code in another application domain that is identified by the specified delegate. //ExecuteAssemblyByName (String) executes the assembly given its display name. //Getlifetimeservice retrieves the current lifetime service object that controls the lifetime policy of this instance. (inherited from MarshalByRefObject.) )//InitializeLifetimeService gives the AppDomain an infinite lifetime by preventing the creation of leases. (Rewrite MarshalByRefObject.InitializeLifetimeService (). )//Iscompatibilityswitchset Gets a nullable Boolean value that indicates whether any compatibility switch is set, or whether the specified compatibility switch is set if it is set. //Isfinalizingforunload Indicates whether this application domain is unloading and whether the common language runtime is terminating the objects that the domain contains. //Reflectiononlygetassemblies Returns an assembly that has been loaded into the reflection-only context of the application domain. //setprincipalpolicy Specifies how the user and identity object should be attached to the thread when it executes in this application domain if the thread tries to bind to the user. //SetThreadPrincipal Sets the default principal object to be attached to the thread when the thread is executing in this application domain, if the thread tries to bind to the principal in this case. //Unload Uninstalls the specified application domain. Console.readkey (); }} from: Http://www.cnblogs.com/kissdodog/archive/2013/05/09/3069553.html

System.AppDomain class

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.