0

My project calls a (non-referenced) DLL project with UI. The end user is supposed to close this form before closing the main form (main project) but sometimes they do not.

I tried using AppDomain.GetAssemblies() to see if the DLL Form is closed. However, even when I close the DLL form, it still shows in the GetAssemblies list. My guess is it remains in the memory until some point?!

What is the best practice to ensure all loaded DLLS from the main project are unloaded and released in memory before allowing the closure of my main project?

amindomeniko
  • 417
  • 6
  • 23

1 Answers1

3

The only way to unload an assembly in .Net is to unload the AppDomain that it was loaded into. This means you need to load additional assemblies into their own app domains This, however, brings in additional complexity as you will not be able to share data between app domains and will have to use inter-process communication technologies to call methods from an assembly loaded into another AppDomain. Depending on your requirements, you may have to inherit your classes from MarshalByRefObject or make them [Serializable].

Some additional information and examples are available in this topic: How to Load an Assembly to AppDomain with all references recursively?

Community
  • 1
  • 1
bib1257
  • 325
  • 2
  • 7