I have an ATL COM exe that I am calling from C#. I import the reference into C# and everything works just fine, the exe is spawned, and I can call functions on it. Now, I instantiate several of these COM objects. Occasionally one of them will hang. Releasing the COM object does nothing, since its still running. I can't kill the process, because I then lose all of my other objects which are behaving just fine. So,
- is there a way to truly kill just one?
- is there a way to launch one exe for each com object requested?
- if my client exits unexpectedly, the COM exe is never cleaned up. Is there any way to fix this?
Ideally, I would be able to launch one COM exe per object instance and have the ability to Process.Kill() it. Are either of these an option? The class I use to create the object is below, RandomID() (artificially) takes a very long time to return in this case. Also, if there is a way to do this in another language, I would be willing to try that out also. Thanks.
public class MyComObject:IDisposable
{
private bool disposed = false;
MyMath test;
public MyComObject()
{
test = new MyMath();
}
public double GetRandomID()
{
if (test != null)
return test.RandomID();
else
return -1;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
if (test != null)
Marshal.ReleaseComObject(test);
disposing = true;
}
}
}
EDIT: It looks like if I can set this to "Single Use" everything will work as I would like. However, I can't find where to set this option in VS 2008
EDIT: Found the answer on google groups
class CMathServerModule : public CAtlExeModuleT< CMathServerModule >
{
public :
DECLARE_LIBID(LIBID_MathServerLib)
DECLARE_REGISTRY_APPID_RESOURCEID(IDR_MATHSERVER, "{2FA977F0-050C-4010-A09F-4FE6D75F3024}")
HRESULT RegisterClassObjects(DWORD dwClsContext, DWORD dwFlags)
throw()
{
dwFlags = ((dwFlags & ~(REGCLS_MULTIPLEUSE | REGCLS_MULTI_SEPARATE )) |
REGCLS_SINGLEUSE);
return CAtlExeModuleT<CMathServerModule>::RegisterClassObjects(dwClsContext, dwFlags);
}
};