How to unload the default .NET AppDomain from an unmanaged application

烂漫一生 提交于 2019-12-11 06:00:08

问题


Is there a way to unload the default .NET AppDomain from an unmanaged application?

I'm using a third party tool called .NET Extender for using .NET assemblies from within Visual FoxPro which allows me to host .NET controls and also make use of .NET classes and methods from within a FoxPro environment.

The problem I'm having is that when debugging an application from within Visual FoxPro it runs the everything under the main vfp9.exe application file for the IDE and it appears that handles to my managed assemblies are not released. So when I make a change to these .NET assemblies and want to update them I have to close the VFP IDE and reopen it otherwise I get a sharing violation when attempting to overwrite the files.

I started looking into ways of ensuring that the controls are disposed but then I came across this article by Rick Strahl where he basically describes that the problem is really that the main AppDomain isn't unloaded. After looking through information about how to unload the default AppDomain I've come to the conclusion that this isn't possible at least from a managed application but is it possible for an unmanaged application. My thought is that just because an unmanaged application has used a .NET resource it shouldn't have to continue to carry around the AppDomain and Runtime baggage.


回答1:


This question was answered on the MSDN Forums and unfortunately it appears that this is not possible and that a process must be terminated to release resources including app domains. This is described in the documentation for the ICLRRuntimeHost.Stop interface method where it states "This method does not release resources to the host, unload application domains, or destroy threads. You must terminate the process to release these resources."



来源:https://stackoverflow.com/questions/2330390/how-to-unload-the-default-net-appdomain-from-an-unmanaged-application

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