I need to call a third party c++ exe (that presents an OLE automation interface) from my app. I'd like to be able to run multiple instances of my app concurrently. The third party app I call has the option of running against different databases.
If I run multiple instances of my app (which calls the third party app) against the same database, all is well.
If I try and run one instance against one database and another instance against another database I get the following error:
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
I suspect that it is due to the second instance not creating a new instance of the third party app but using the same instance as the first copy of my app.
Does this sound likely? I suspect so as if I look in Task Manager I can only see one copy of the third party app running in background processes, but two copies of my app running in Apps.
So,how do I force my app to create a second instance of the third party app?
Code:
Type tpType = Type.GetTypeFromProgID("thirdPty.Application");
dynamic comObject = Activator.CreateInstance(tpType);
try
{
bool success = comObject.LoadDatabase(dbPath);
if (success)
{
var newTp = comObject.Open(inputFile);
newTp.Run(runType);
while (newTp.IsBusy)
{
// wait for process to finish
Thread.Sleep(500);
}
newAb.Export(outputFolder + "\\output" + " " + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".csv");
newAb.Close();
}
}
I don't think you can. When you call Activator.CreateInstance
, it's up to the (D)COM server how it instantiates it's Application COM objects.
Apparently, this one is registered with REGCLS_MULTIPLEUSE
, meaning multiple instance will be served from the same server process. One would assume that if that is designed behaviour of the COM server, it should also behave nicely when using different database connections for each Application object.
User contributions licensed under CC BY-SA 3.0