在操作系統中
在
當我們運行一個
一個進程中可以有多個AppDomain
並且默認AppDomain是不能被卸載的
using System;
using System
using System
using System
using System
using System
using Ark
/// <summary>
/// The local loader
/// </summary>
public class AssemblyDynamicLoader
{
/// <summary>
/// The log util
/// </summary>
private static ILog log = LogManager
/// <summary>
/// The new appdomain
/// </summary>
private AppDomain appDomain;
/// <summary>
/// The remote loader
/// </summary>
private RemoteLoader remoteLoader;
/// <summary>
/// Initializes a new instance of the <see cref=
/// </summary>
public AssemblyDynamicLoader()
{
AppDomainSetup setup = new AppDomainSetup();
setup
setup
setup
setup
setup
setup
this
String name = Assembly
this
}
/// <summary>
/// Invokes the method
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
/// <returns>The output of excuting
public String InvokeMethod(String fullName
{
this
return this
}
/// <summary>
/// Unloads this instance
/// </summary>
public void Unload()
{
try
{
AppDomain
this
}
catch (CannotUnloadAppDomainException ex)
{
log
}
}
}
(在不同AppDomain間傳遞對象
using System;
using System
using System
using System
using System
using System
/// <summary>
/// The Remote loader
/// </summary>
public class RemoteLoader : MarshalByRefObject
{
/// <summary>
/// The assembly we need
/// </summary>
private Assembly assembly = null;
/// <summary>
/// The output
/// </summary>
private String output = String
/// <summary>
/// Gets the output
/// </summary>
/// <value>The output
public String Output
{
get
{
return this
}
}
/// <summary>
/// Invokes the method
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
public void InvokeMethod(String fullName
{
this
this
try
{
this
Type pgmType = null;
if (this
{
pgmType = this
}
else
{
pgmType = Type
}
Object[] args = RunJob
BindingFlags defaultBinding = BindingFlags
| BindingFlags
| BindingFlags
CultureInfo cultureInfo = new CultureInfo(
try
{
MethodInfo methisInfo = RunJob
if (methisInfo == null)
{
this
}
if (methisInfo
{
if (methisInfo
{
if (methisInfo
{
pgmType
this
}
else
{
this
}
}
else
{
if (methisInfo
{
pgmType
this
}
else
{
this
}
}
}
else
{
if (methisInfo
{
object pgmClass = Activator
if (methisInfo
{
pgmType
this
}
else
{
this
}
}
else
{
object pgmClass = Activator
if (methisInfo
{
pgmType
this
}
else
{
this
}
}
}
}
catch
{
this
}
}
catch (Exception e)
{
this
}
}
}
其中的InvokeMethod方法只要提供Assembly的全名
其全名就可以執行該方法
最後這樣使用這兩個類
AssemblyDynamicLoader loader = new AssemblyDynamicLoader();
String output = loader
loader
From:http://tw.wingwit.com/Article/program/net/201311/11489.html