Unloading AppDomains

Suppose I have an AppDomainA that will launch AppDomainB. Then, AppDomainB launches AppDomainC.

If I unload AppDomainB in AppDomainA, does AppDomainC also unload, or should I handle this myself?

+6
source share
1 answer

The best way to find out is to try. Here is an example of creating an AppDomainA that creates an AppDomainB. We say B to do some work, and unload A.

internal class Program { private static Timer _timer; private static void Main(string[] args) { var domainA = AppDomain.CreateDomain("AppDomainA"); domainA.DomainUnload += (s, e) => Console.WriteLine("DomainA was unloaded."); domainA.DoCallBack(() => { var domainB = AppDomain.CreateDomain("AppDomainB"); domainB.DomainUnload += (s, e) => Console.WriteLine("DomainB was unloaded."); domainB.DoCallBack(() => { _timer = new Timer(o => { Console.WriteLine("Tick from AppDomain: " + AppDomain.CurrentDomain.FriendlyName); }, null, 0, 1000); }); }); AppDomain.Unload(domainA); Application.Run(); //Run a message loop so AppDomainB can keep doing work. } } 

We see that we are receiving the AppDomainA message, which was unloaded, but not B, but B continues to work. Our conclusion is that you need to verify this yourself.

+1
source

All Articles