Is there any way to determine the PID of a process that was started by instantiating a COM coclass?
有没有办法确定通过实例化COM coclass启动的进程的PID?
For example:
MyApp.ApplicationClass anApp = new MyApp.ApplicationClass();
would start the process myapp. Potentially there are already a lot of myapp processes running when this code is executed.
会启动进程myapp。执行此代码时,可能已经有很多myapp进程在运行。
My current solution to acquire the latest PID feels a bit awkward: I memorize the list of running processes before creating the new instance and take the delta of running myapp PIDs when the new instance was created.
我目前获得最新PID的解决方案感觉有点尴尬:我在创建新实例之前记住正在运行的进程列表,并在创建新实例时采用运行myapp PID的增量。
Is there an standard/better way to accomplish this?
是否有标准/更好的方法来实现这一目标?
Edit: The PID is later used to identify/monitor the created process.
编辑:PID稍后用于识别/监控创建的过程。
1 个解决方案
#1
It looks like you also control the code for MyApp
?
看起来你也控制了MyApp的代码?
If so, I'd recommend the best way to do this is to add a method to MyApp called GetPid()
, and just call anApp.GetPid()
...
如果是这样,我建议最好的方法是向MyApp添加一个名为GetPid()的方法,然后调用anApp.GetPid()...
#1
It looks like you also control the code for MyApp
?
看起来你也控制了MyApp的代码?
If so, I'd recommend the best way to do this is to add a method to MyApp called GetPid()
, and just call anApp.GetPid()
...
如果是这样,我建议最好的方法是向MyApp添加一个名为GetPid()的方法,然后调用anApp.GetPid()...