简体   繁体   English

从 C# 杀死一个进程外 COM object

[英]Killing an out of process COM object from C#

I have an out of process COM object that we are calling from C# using dllhost (we were unable to use COM+).我有一个进程外的 COM object,我们使用 dllhost 从 C# 调用它(我们无法使用 COM+)。 This works great, and I have my own pool of objects that I can use whenever I want.这很好用,而且我有自己的对象池,可以随时使用。 The COM object will be reused many times and is long running (> 20 minutes sometimes). COM object 将被重复使用多次并且运行时间很长(有时> 20分钟)。 Unfortunately, this is an old VB ActiveX dll that occasionally hangs.不幸的是,这是一个偶尔挂起的旧 VB ActiveX dll。 So, I need to be able to kill it.所以,我需要能够杀死它。 I've tried releasing the COM object explicitly and then garbage collecting from another thread, but that does nothing.我已经尝试明确释放 COM object 然后从另一个线程进行垃圾收集,但这没有任何作用。 Does anyone have any ideas other than grabbing the PID of dllhost and killing that when I spin it up (probably not that safe)?除了获取 dllhost 的 PID 并在我启动它时将其杀死(可能不那么安全)之外,还有其他人有什么想法吗? Thanks for the help.谢谢您的帮助。

I've tried我试过了

System.Runtime.InteropServices.Marshal.ReleaseComObject(m_MyObj);
GC.Collect();
GC.WaitForPendingFinalizers();
m_MyObj = null;

and I create it by我创建它

 uint hResult = Ole32Methods.CoCreateInstance(ref CalcServerGuid, null, (uint)CLSCTX.CLSCTX_LOCAL_SERVER, ref IID_IUnknown,
            out CalcServerInstance);

If I understand you are running a VB6 COM object and you say within dllhost.如果我知道您正在运行 VB6 COM object 并且您在 dllhost 中说。 This implies to me that this is a configured component running under COM+.这对我来说意味着这是一个在 COM+ 下运行的配置组件。 If this is a server application you could using the COM+ admin catalog shutdown the server application.如果这是一个服务器应用程序,您可以使用 COM+ 管理目录关闭服务器应用程序。

FYI dllhost is the COM+ hosting process.仅供参考 dllhost 是 COM+ 托管进程。

Why are you using CoCreateInstance?为什么要使用 CoCreateInstance? Instead of importing a wraper and using the .net bcl to create the object.而不是导入包装器并使用 .net bcl 来创建 object。

My only other thought is your better to resolve the issue of the hang then trying to shutdown the pool.我唯一的另一个想法是您最好解决挂起问题,然后尝试关闭池。 Are you actually using object pooling in your VB via COM+?您实际上是在通过 COM+ 在您的 VB 中使用 object 池吗? I seem to recall that pooling can't be done with a VB6 COM object without hacking outside the constraints of VB6.我似乎记得如果没有超出 VB6 COM object 的限制,则无法使用 VB6 COM object 完成池化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM