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

查看:20
本文介绍了如何从非托管应用程序卸载默认的 .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.

我开始研究确保处理控件的方法,但后来我遇到了 Rick Strahl 撰写的这篇文章 他基本上描述了问题实际上是主 AppDomain 没有卸载.在查看了有关如何卸载默认 AppDomain 的信息后,我得出的结论是,这至少从托管应用程序中是不可能的,但对于非托管应用程序来说是可能的.我的想法是,仅仅因为非托管应用程序使用了 .NET 资源,它不应该继续携带 AppDomain 和运行时包.

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.

推荐答案

此问题已在 MSDN 论坛 不幸的是,这似乎是不可能的,必须终止进程才能释放包括应用程序域在内的资源.这在 ICLRRuntimeHost.Stop 接口方法的文档中有所描述,其中它指出此方法不会向主机释放资源、卸载应用程序域或销毁线程.您必须终止进程才能释放这些资源."

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天全站免登陆