How to properly unload an AppDomain using C#?

后端 未结 2 1991
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 10:55

I have an application that loads external assemblies which I have no control over (similar to a plugin model where other people create and develop assemblies that are used b

2条回答
  •  抹茶落季
    2020-12-16 11:50

    Try to make GC.Collect() if you do not unload the domain.

     try
        {
           AppDomain.Unload(otherAssemblyDomain);
        }
        catch (CannotUnloadAppDomainException)
        {
           GC.Collect();
           AppDomain.Unload(otherAssemblyDomain);
        }
    

提交回复
热议问题