AppDomain介绍
一、建立控制台项目
二、更改Program为ADSetp
三、去掉命名空间AppDomain.CurrentDomain
四、贴代码
using System; using System.IO; using System.Reflection; using System.Security.Policy; using System.Collections.Generic; using System.Linq; using System.Text; class ADSetup { public static void Main() { // Create application domain setup information var domaininfo = new AppDomainSetup(); domaininfo.ConfigurationFile = System.Environment.CurrentDirectory + Path.DirectorySeparatorChar + "ADSetup.exe.config"; domaininfo.ApplicationBase = System.Environment.CurrentDirectory; //Create evidence for the new appdomain from evidence of the current application domain Evidence adEvidence = AppDomain.CurrentDomain.Evidence; // Create appdomain AppDomain domain = AppDomain.CreateDomain("Domain2", adEvidence, domaininfo); // Display application domain information. Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName); Console.WriteLine("Child domain: " + domain.FriendlyName); Console.WriteLine(); Console.WriteLine("Configuration file: " + domain.SetupInformation.ConfigurationFile); Console.WriteLine("Application Base Directory: " + domain.BaseDirectory); AppDomain.Unload(domain); Console.ReadKey(); } }
五、运行结果
Host domain: AppDomain.CurrentDomain.vshost.exe Child domain: Domain2 Configuration file: c:\users\huqian\documents\visual studio 2015\Projects\AppDomain.CurrentDomain\AppDomain.CurrentDomain\bin\Debug\ADSetup.exe.config Application Base Directory: c:\users\huqian\documents\visual studio 2015\Projects\AppDomain.CurrentDomain\AppDomain.CurrentDomain\bin\Debug