接下來在原來基礎上需要修改的是
· 將編譯成的DLL保存到磁盤中
· 創建另外的AppDomain
· 獲得IRemoteInterface接口的引用
· 調用InvokeMethod方法來遠程調用
· 可以通過AppDomain
以下是完整的代碼
//get the code to compile
string strSourceCode = this
//
AppDomainSetup objSetup = new AppDomainSetup();
objSetup
AppDomain objAppDomain = AppDomain
//
CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();
//
CompilerParameters objCompilerParameters = new CompilerParameters();
objCompilerParameters
objCompilerParameters
// Load the remote loader interface
objCompilerParameters
// Load the resulting assembly into memory
objCompilerParameters
objCompilerParameters
//
CompilerResults cr = objCSharpCodePrivoder
if (cr
{
string strErrorMsg = cr
for (int x =
{
strErrorMsg = strErrorMsg +
cr
cr
}
this
MessageBox
return;
}
//
RemoteLoaderFactory factory = (RemoteLoaderFactory)objAppDomain
// with help of factory
object objObject = factory
if (objObject == null)
{
this
return;
}
// *** Cast object to remote interface
IRemoteInterface objRemote = (IRemoteInterface)objObject;
object[] objCodeParms = new object[
objCodeParms[
string strResult = (string)objRemote
this
//Dispose the objects and unload the generated DLLs
objRemote = null;
AppDomain
System
[
From:http://tw.wingwit.com/Article/program/net/201311/14505.html