System.EnterpriseServices.RegistrationHelper不会发布文件 [英] System.EnterpriseServices.RegistrationHelper Doesn't Release File

查看:65
本文介绍了System.EnterpriseServices.RegistrationHelper不会发布文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们开发了一个小型MMC管理单元,用于安装应用程序的各种组件.特别是,它使用System.EnterpriseServices.RegistrationHelper向COM +注册.NET程序集.逻辑很简单:首先,卸载现有程序集,然后复制新文件,然后安装新程序集.代码如下:

We developed a small MMC snap-in that installs various components of the application. In particular, it registers .NET assemblies with COM+ using System.EnterpriseServices.RegistrationHelper. The logic is simple: first, uninstall existing assembly, then copy new file over, then install the new assembly. The code looks like this:

if (File.Exists(destination))
{
   try
    {
       new RegistrationHelper().UninstallAssembly(destination, ComPlusHelper.ApplicationName);
    }
    catch (Exception ex)
    {
        Log.LogError(...);
    }
}
File.Copy(source, destination, true);

但是,File.Copy调用失败,并显示错误该进程无法访问文件xxxx,因为它正在被另一个进程使用".我花了一天的时间阅读MSDN和谷歌搜索,但找不到解决方案.

However, the File.Copy call fails with the error "The process cannot access the file xxxx because it is being used by another process". I spent a day reading MSDN and googling, but couldn't find a solution.

有人有什么建议吗?

推荐答案

如果COM +应用程序正在运行,它将继续保持文件打开状态.任何时候要删除组件,都应在删除组件时禁用并关闭该应用程序,然后再重新启用该应用程序.

If the COM+ application is running, it will continue to hold the file open. Any time you want to remove components, you should disable and shutdown the application while removing the component, then enable the application again afterwards.

您必须使用ICOMAdminCatalog或ICOMAdminCatalog2系列接口来执行此操作.任何搜索引擎都会出现许多在VBScript中执行以下任务的示例.我不知道有关COM +管理的任何.NET包装项目.

You have to use the ICOMAdminCatalog or ICOMAdminCatalog2 family of interfaces to do this. Any search engine will turn up numerous examples of doing the following tasks in VBScript. I am not aware of any .NET wrapper projects around COM+ administration.

我认为是最佳实践的逻辑流程:

A flow of the logic that I think is a best practice:

  1. 禁用该应用程序
  2. 关闭应用程序
  3. 监控并等待正在进行的通话关闭
  4. 卸载组件
  5. 启用应用程序

您也可以启动该应用程序,但是它应该在下一次调用该应用程序时自动启动.

You can start the application as well, but it should start automatically with the next call to the application.

每个步骤都使用管理类的不同方面,其中一些已经作为单独的答案解决了.

Each of these steps uses different aspects of the administration classes, and some of them are already solved as individual answers.

在编写COM +管理代码之前,您应该了解系统的层次结构.Microsoft已对此进行了详细记录:http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms687763%28v=vs.85%29.aspx

Before you write COM+ administration code, you should understand the hierarchy of the system. Microsoft has this well documented: http://msdn.microsoft.com/en-us/library/windows/desktop/ms687763%28v=vs.85%29.aspx

您将需要从应用程序"集合中获取应用程序.要设置的属性为"IsEnabled".不要忘记在更改属性后保存更改.

You will need to fetch the Application from the Applications collection. The property to set is "IsEnabled". Don't forget to save changes after changing the property.

这是一个很好的答案:如何从.NET重新启动远程服务器上的COM +应用程序?

Here's a good answer: How do I restart a COM+ application on a remote server from .NET?

可以在未运行的应用程序上调用ShutdownApplication.

It is safe to call ShutdownApplication on an application that is not running.

您需要在ApplicationInstances集合中查找该应用程序.如果未找到它,则它必须已关闭(或从未在任何位置运行过).如果找到了它,请睡眠一段可接受的时间,然后从刷新的集合实例中再次寻找它.

You'll need to look for the application in the ApplicationInstances collection. If it is not found, then it must have shut down (or was never running in the first place). If it is found, sleep for an acceptable period of time and look for it again from a refreshed instance of the collection.

您已经解决了这一部分.

You've got this part solved already.

启用过程与禁用应用程序相同,但是具有不同的IsEnabled属性值.

The process of enabling is the same as you followed for disabling the application, but with a different IsEnabled property value.

这篇关于System.EnterpriseServices.RegistrationHelper不会发布文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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