简体   繁体   English

Activator.CreateInstance我的实例吗?

[英]Activator.CreateInstance my instance?

I have a piece of code to open an instance of a COM object and perform different tasks. 我有一段代码可以打开COM对象的实例并执行不同的任务。 My problem is that if the application that I open with COM is already running then I reuse that instance. 我的问题是,如果我使用COM打开的应用程序已经在运行,那么我将重用该实例。 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();

This is a property of the COM server itself. 这是COM服务器本身的属性。 The value it passes for the flags argument in the CoRegisterClassObject() call. 它为CoRegisterClassObject()调用中的flags参数传递的值。 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. 听起来好像正在传递REGCLS_MULTIPLEUSE,这并不罕见,因为为每个单独的客户端启动新流程可能会很昂贵。

The client cannot change that behavior. 客户端无法更改该行为。 You'll need help from the vendor, maybe there's a configuration file. 您需要供应商的帮助,也许有一个配置文件。

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

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