Code example of multiple .NET AppDomains

Reading the MSDN actually provides some good information.

http://msdn.microsoft.com/en-us/library/system.appdomain.aspx

--Dan


I have used this in the following context (don't have the code handy with me right now to post)

  • Create a new AppDomain (e.g. appDomainX)
  • Create a new instance of an object using this new domain
  • The new object (lived in the new object) loads a bunch of assemblies
  • Reflect on them to collect some metrics
  • Get the result produced
  • Unload appDomainX

The benefit of this is that you can unload assemblies loaded into the newly created AppDomain. If you are doing this on your main AppDomain over and over again loading more assemblies, your AppDomain will grow monstrously. Creating a separate AppDomain allows you to unload after each inspection which in turn unload all the assemblies loaded to that domain hence the main AppDomain remains clean.

Tags:

.Net

Appdomain