문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top