问题描述
我有一个带有 Shared 属性的 VB.NET COM 类,比如 ABC.问题是该组件被几个 C++ COM exe 使用,所以我的理解是他们每个人都会获得自己的程序集负载,并且 Shared 属性对于每个 EXE 都是唯一的.有没有办法为这个程序集获取一个跨 EXE 共享属性?
I have a VB.NET COM class with a Shared property, like ABC. The problem is the component is used by several C++ COM exe, so its my understanding that they each will get their own assembly load, and the Shared property will be unique to each EXE. Is there a way to get for this assembly a cross EXE shared property ?
发送.
推荐答案
您所描述的将通过创建进程外 COM 服务器(通常也称为 ActiveX EXE)在本机 COM 中轻松"完成.顾名思义,进程外 COM 服务器在其自己的进程中运行,并通过 COM 接口为其方法提供服务.如果多个客户端同时使用 COM 服务器,它们都共享同一个服务器进程,因此该进程中的任何全局数据都将在所有客户端之间共享.
What you are describing would be "easily" accomplished in native COM by creating an out-of-process COM server (also commonly referred to as an ActiveX EXE). As the name implies, an out-of-process COM server runs in its own process and serves it's methods via a COM interface. If multiple clients use the COM server simultaneously, they both share the same server process, so any global data within that process is shared between all of the clients.
不幸的是,.NET 没有提供任何机制来创建进程外 COM 服务器.所有 COM 可见的 .NET 程序集都充当进程内 COM 库,因此每个使用它的客户端在他们自己的进程中都有自己的一组全局数据.
Unfortunately, .NET does not provide any mechanism for creating an out-of-process COM server. All COM visible .NET assemblies act as in-process COM libraries, so each client using it has it's own set of global data within their own processes.
唯一的选择是创建一个标准的进程内 COM 可见库,但让它只是一个调用其他进程的传递包装器..NET 中的进程间通信通常由 WCF 处理,因此典型的解决方案是让 WCF 服务在 COM 可见库与之通信的后端运行.如果您不想使用 WCF,还可以查看 .NET Remoting 或原始 TCP/IP 套接字.
The only alternative is to create a standard in-process COM-visible library, but have it just be a pass-through wrapper which calls out to some other process. Inter-process communication in .NET is typically handled with WCF, so the typical solution would be to have a WCF service running in the back-end with which the COM-visible library communicates. If you don't want to use WCF, you could also look at .NET Remoting or raw TCP/IP sockets.
这是一个小鸡抓图,可以帮助我理解我的意思:
Here's a chicken-scratch diagram to help visualize what I mean:
这篇关于需要跨我的 COM 服务器实例共享属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!