System.EnterpriseServices.RegistrationHelper不释放文件 [英] System.EnterpriseServices.RegistrationHelper Doesn't Release File

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

问题描述

我们开发了一个小型的MMC管理单元中安装应用程序的各种组件。特别是,它使用System.EnterpriseServices.RegistrationHelper注册.NET程序集与COM +。道理很简单:首先,卸载现有的装配,然后复制新的文件覆盖,然后再安装新组件。在code是这样的:

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 +管理code,你应该明白了系统的层次结构。微软这个有据可查:的http://msdn.microsoft.com/en-us/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

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