Unloading Application Domain does not return?

末鹿安然 提交于 2019-12-10 21:31:22

问题


My question is about application domain created for loading/unloading dlls. All started with the need of

Step-1 : load the dll
Step-2 : process that dll
Step-3 : Unload the dll

As we can not unload a dll, creating an Application Domain is inevitable, which is fine. So new steps are;

Step-1 : Create a new app domain
Step-2 : load the dll
Step-3 : process that dll
Step-4 : Unload the Application domain

My problem is about unloading part. Sometimes AppDomain.Unload("newDomain"); does not return although i wait quite long. What may be the reason for the unload method not to return? I have read MSDN for the following explanation.

When a thread calls Unload, the target domain is marked for unloading. The dedicated thread attempts to unload the domain, and all threads in the domain are aborted. If a thread does not abort, for example because it is executing unmanaged code, or because it is executing a finally block, then after a period of time a CannotUnloadAppDomainException is thrown in the thread that originally called Unload. If the thread that could not be aborted eventually ends, the target domain is not unloaded. Thus, in the .NET Framework version 2.0 domain is not guaranteed to unload, because it might not be possible to terminate executing threads.

But i have some questions.
1) What is the "Period of time" explained here? Can i set it?
2) MSDN says .NET 2.0 framework does not quarante to unload. How about .NET 4.0?
3) I am sure there is no thread running in the loaded dll. What may be the other reason?

i am badly stuck, any help is appreciated :(

来源:https://stackoverflow.com/questions/25651497/unloading-application-domain-does-not-return

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!