如何从非托管应用程序中卸载默认的.NET AppDomain [英] How to unload the default .NET AppDomain from an unmanaged application

查看:93
本文介绍了如何从非托管应用程序中卸载默认的.NET AppDomain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从不受管的应用程序中卸载默认的.NET AppDomain?

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

我正在使用名为 .NET Extender 在Visual FoxPro中使用.NET程序集,这使我可以托管.NET控件,还可以在FoxPro环境中使用.NET类和方法.

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.

我遇到的问题是,当从Visual FoxPro中调试应用程序时,它将在IDE的主vfp9.exe应用程序文件下运行所有​​内容,并且似乎未释放托管组件的句柄.因此,当我对这些.NET程序集进行更改并想要更新它们时,必须关闭VFP IDE并重新打开它,否则在尝试覆盖文件时会遇到共享冲突.

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.

推荐答案

文档中对此进行了描述,其中它指出:此方法不会向主机释放资源,卸载应用程序域或破坏线程.您必须终止进程才能释放这些资源."

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."

这篇关于如何从非托管应用程序中卸载默认的.NET AppDomain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆