window 命令大全
/*主要说明如何通过反射实现动态加载 DLL,
* 因为.Net 底层有自动回收机制,所以不需要考虑这个问题
* ADD by Brian 2008/01/21 参考 MSDN
*/
using System;
using System.IO;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Remoting;
namespace DynamicIncreaseDLL
{
#region
class DynamicLoadDLL
{
[STAThread]
static void Main(string[] args)
{
string sCallDomainName = Thread.GetDomain().FriendlyName;
Console.WriteLine(sCallDomainName);
//创建一个动态程序域
Console.WriteLine("请输入动态程序域名称");
string sAD = Console.ReadLine();
AppDomain ad = AppDomain.CreateDomain(sAD);
//实例化一个 ProxyObject 这个类型的对象 这个是需要加载 DLL 的对象
ProxyObject obj = (ProxyObject)ad.CreateInstanceAndUnwrap("DynamicIncreaseDLL",
"DynamicIncreaseDLL.ProxyObject");
//自己抓一个需要动态加载的 DLL 的文件名(包含文件路径)
string sFileName = Environment.CurrentDirectory + "\" + "gmrbrian.exe";
obj.LoadAssembly(sFileName);
obj.Invoke("类名", "构造方法名", "主程序方法参数");
AppDomain.Unload(ad);
obj = null;
Console.ReadLine();
}
}
class ProxyObject : MarshalByRefObject
{
Assembly asbly = null;
//加载包含路径的文件
public void LoadAssembly(string AFileName)
{
asbly = Assembly.LoadFile(AFileName);
}
//实例化该类
public bool Invoke(string AFullClassName, string AMethodName, params Object[] args)
{
if (asbly == null)
return false;