Esteban
Esteban

Reputation: 179

vb.net - How do I selectively communicate with two instances of a program?

I'm new to VB, and so forgive me if this is a simple question.

I will be running multiple time consuming (single thread) processes in a program (that allows automation thru COM). And so to save some time, I want to open two or more instances of this program and run them simultaneously. But anything that I try to do on the program, it happens on the first opened program. This is what I have which my intentions are to open two instances of the program (which does correctly), and open a new document in each of the instances (which what it does is open two new documents in myProcess0 and none in myProcess1. Note: I have System.Diagnostics namespace activated.

    Using myProcess0 As Process = Process.Start(programPath)
        myProcess0.WaitForInputIdle()
        pws0 = New COMprogram.Document
    End Using

    Using myProcess1 As Process = Process.Start(programPath)
        myProcess1.WaitForInputIdle()
        pws1 = New COMprogram.Document
    End Using

Note: The COM program does not allow to create an handle for the program (like Matlab allows with MLApp.MLApp)

Any help will be appreciated it! Thanks in advance!

Upvotes: 3

Views: 335

Answers (2)

Esteban
Esteban

Reputation: 179

This is not exactly a solution, but my current "brute" workaround. This works if your iterations are independent of each other and wish to use multiple instances of a program in the same computer to perform these iterations (but for some reason that is unknown to me, any "Application" objects created point back only to the first instance of the Application).

What I'm doing, is tricking the code by using "desktops": http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx

I simply open the VB code and a Application instance in each desktop, and for some reason the VB code only interacts with the Application opened in the current desktop and not on the others. This happens as well with Matlab somehow. For some reason, all Matlab Application objects reference the first instance.

Upvotes: 1

Mark Hurd
Mark Hurd

Reputation: 10931

This will be up to the COMprogram API. With Word or Excel, for example, you can't specify which instance you're accessing without manipulating an Application object.

Upvotes: 0

Related Questions