标签:string 垃圾 process system main [] namespace names app
新知识点:
运行示例:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Reflection; using System.Runtime.Remoting; namespace FactoryMode { [Serializable] public class Program : MarshalByRefObject { //在调用此方法时,观察"调用堆栈",发现一次"外部代码"的切换,表明自进行了一次跨域操作 public void NotMainMethod() { //AppDomain.CurrentDomain 可以得到同样的结果 var curCallingDomain = Thread.GetDomain(); var curCallingDomainName = curCallingDomain.FriendlyName; Console.WriteLine("Cross-domain calling, curdomain name={0}.", curCallingDomainName); } static void Main(string[] args) { var curCallingDomain = Thread.GetDomain(); var curCallingDomainName = curCallingDomain.FriendlyName; Console.WriteLine("Default AppDomain‘s friendly name={0}.", curCallingDomainName); string exeAssembly = Assembly.GetExecutingAssembly().CodeBase; Console.WriteLine("Main assembly={0}.", exeAssembly); AppDomain otherDomain = null; Console.WriteLine("{0}Demo #1", Environment.NewLine); otherDomain = AppDomain.CreateDomain("AD #2", null, null); //在"AD#2"应用程序域中创建 Programs 对象,并向默认应用程序域返回它的引用; var mbrt = (Program)otherDomain.CreateInstanceFromAndUnwrap(exeAssembly, "FactoryMode.Program"); Console.WriteLine("Type={0}", mbrt.GetType()); Console.WriteLine("Is proxy={0}", RemotingServices.IsTransparentProxy(mbrt)); //利用引用调用方法,方法中的打印显示出此时线程正运行在"AD#2"应用程序域中 mbrt.NotMainMethod(); Console.Read(); } } }
卸载AppDomain:
监视AppDomain:
非常好用的功能,可以用来做资源监控,性能监测;
标签:string 垃圾 process system main [] namespace names app
原文地址:http://www.cnblogs.com/Daniel-Liang/p/6034917.html