tags:

views:

53

answers:

1

I have a piece of code to open an instance of a COM object and perform different tasks. My problem is that if the application that I open with COM is already running then I reuse that instance. I would always like to have new instance and work with that and finally close. Anyway to do that?

Type t = System.Type.GetTypeFromProgID("QlikTech.QlikView");
QlikView.Application app = (QlikView.Application)Activator.CreateInstance(t);
app.OpenDocEx("c:\\test.qvw",1,false,null,null,null,true);
String script = app.ActiveDocument().GetScript();
StreamWriter outfile = new StreamWriter("c:\\test.qvw.txt");
outfile.Write(script);
outfile.Close();
app.Quit();
+2  A: 

This is a property of the COM server itself. The value it passes for the flags argument in the CoRegisterClassObject() call. Sounds like it is passing REGCLS_MULTIPLEUSE, which is not uncommon since it can be expensive to start a new process for each individual client.

The client cannot change that behavior. You'll need help from the vendor, maybe there's a configuration file.

Hans Passant
+1. And in some cases, REGCLS_MULTIPLEUSE may be required, i.e. the service provided may require that all instances are served from the same process.
Joe