Supose I have AppDomainA, which spins up AppDomainB. AppDomainB then spins up AppDomainC.
If, within AppDomainA I unload AppDomainB, does AppDomainC also get unloaded or must I make sure to handle that on my own?
Best way to find out is to try it. Here is an example of creating AppDomainA, which creates AppDomainB. We tell 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 we get the message AppDomainA was unloaded, but not B, and B keeps working. Our conclusion is you need to make sure to handle this on your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With