我有一个属性,其实例我想在其他域.
- public ModuleLoader Loader
- {
- get
- {
- if(_loader == null)
- _loader = (ModuleLoader)myDomain.CreateInstanceAndUnwrap(
- this.GetType().Assembly.FullName,"ModuleLoader",false,System.Reflection.BindingFlags.CreateInstance,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.由于主应用程序还想观看模块的一些活动,并且与在单独域中运行的对象进行交互,那么实现它的最佳方式是什么.