我有一個屬性的實例,我想在其他域。CreateInstanceAndUnwrap和域
public ModuleLoader Loader
{
get
{
if(_loader == null)
_loader = (ModuleLoader)myDomain.CreateInstanceAndUnwrap(
this.GetType().Assembly.FullName,
"ModuleLoader",
false,
System.Reflection.BindingFlags.CreateInstance,
null,
null,
null,
null);
System.Diagnostics.Debug.WriteLine("Is proxy={0}",
RemotingServices.IsTransparentProxy(_loader));
//writes false
_loader.Session = this;
return _loader;
}
}
這工作正常。但我假設_loader實例上的所有方法調用都會在其他域(myDomain)中調用。但是當我運行下面的代碼時,它仍然寫入主應用程序域。
public void LoadModule(string moduleAssembly)
{
System.Diagnostics.Debug.WriteLine("Is proxy={0}",
RemotingServices.IsTransparentProxy(this));
System.Diagnostics.Debug.WriteLine(
AppDomain.CurrentDomain.FriendlyName);
System.Diagnostics.Debug.WriteLine("-----------");
}
是因爲Unwrap()?我在哪裏做錯了?
我知道AppDomain會創建單獨的內存。我需要的是我的主應用程序運行,它將模塊加載到不同的AppDomain中。由於主應用程序也希望觀察模塊的某些活動並與在單獨域中運行的對象進行交易,因此實現它的最佳方式是什麼。
希望我可以加+100 – Igorek