tags:

views:

449

answers:

1

I have an out of process COM object that we are calling from C# using dllhost (we were unable to use 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). Unfortunately, this is an old VB ActiveX dll that occasionally hangs. 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. Does anyone have any ideas other than grabbing the PID of dllhost and killing that when I spin it up (probably not that safe)? 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);
A: 

If I understand you are running a VB6 COM object and you say within dllhost. This implies to me that this is a configured component running under COM+. If this is a server application you could using the COM+ admin catalog shutdown the server application.

FYI dllhost is the COM+ hosting process.

Why are you using CoCreateInstance? Instead of importing a wraper and using the .net bcl to create the 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+? I seem to recall that pooling can't be done with a VB6 COM object without hacking outside the constraints of VB6.

JoshBerke
Hi Josh, I'm not using COM+, I'm using dllhost directly (it involves changing a couple of registry keys and instantiating as above). I create the pool of the out of proc objects internally in my program. We were unable to use COM+ due to client side restrictions.
Steve
heh ouch ok sounds painful. Are you using a RCW? To wrap the com object. There was a method that released all references to a RCW. I think it was on Marshall. I think Kev is right time to rewrite;-)
JoshBerke
@Steve Can you control under which user dllhost.exe is started?
sharptooth