I am having trouble figuring something out about my AppDomain.Unload(...)
call. I have a detailed explanation with code from my earlier question. As it turns ou
As I suspected, instancing with the IModule interface in the primary domain causes a leak. In order to do this properly:
AppDomain domain = AppDomain.CreateDomain(domainName);
HostDomains[domainName] = domain; // put in collection
ModuleAdapter adapter = (ModuleAdapter)domain.CreateInstanceAndUnwrap(asmName , typeName);
where ModuleAdapter inherits MarshalByRefObject
. Then:
adapter.Execute(moduleAssembly , moduleType);
Inside the ModuleAdapter class:
public void Execute(string Name, string EntryPoint)
{
module = (IModule)AppDomain.CurrentDomain.CreateInstanceAndUnwrap(Name , EntryPoint);
}
I do welcome comments or additional answers for a better way.
After moving the instancing to the ModuleAdapter class, we are still having the issue with AppDomain.Unload killing the entire application. I was wondering if this is because in the module plugin we are using Application.Run(myForm)
- then when we shutdown we call myForm.Close(). Obviously this shuts down the application so I was wondering if the myForm.Close() also 'unloads' the AppDomain.