LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two Instances of an Executable

I have an exectable that I need to run one or two instances of.  In other words, when the user clicks on the shortcut or the exe the first time, the first instance runs.  When the user does that the second time, a second instance runs.  When the user does that a third time or subsequent times, display a message stating that two instances are already running and then close the third instance.

 

I have the application setup to run multiple instances, as shown in other threads, that was done by adding the following line to the ini file:

allowmultipleinstances=true

 

What are the options for limiting the number of instances to a maximum of 2?

 

Thanks,

Hans 

0 Kudos
Message 1 of 4
(2,494 Views)

None, as far as I know.

 

As an alternative you can simply use your own key in your app's config file to keep track of how many instances are open.

0 Kudos
Message 2 of 4
(2,481 Views)

Thanks for the reply.  My interpretation of what you're saying is to create a key in the app config file such as "number of active instances" and have the app increment it each time an instance is started and decrement it each time an instance is exited.  Am I interpreting correctly?

 

If so, one catch to that approach would be that if an instance was exited in such a way that the key decrement code did not run (if task manager was used to stop the process for example), then the app config file would no longer reflect the correct number of instances.  The app config file would then have to be edited manually to correct the key value.

 

The best solution I've thought of is if the LabVIEW runtime engine could read an app config file line like:

maxnumberof instances=2

 

Or perhaps the runtime engine could be queried to see how many instances of an app are running.  The LabVIEW runtime engine must know that.  Is there a programmatic way to query the number of active instances?

 

Thanks again,

Hans 

0 Kudos
Message 3 of 4
(2,461 Views)

You could trying using the OS API function to get a list of open processes and identify them by name. There should be some examples for this for Windows floating online using .NET or the API functions.

 

Alternatively, you can try creating your own service for this. When you start your app, try opening a VI server or TCP connection to a designated port. If it fails, you know the service is closed and you can run it (using the system exec VI, since you want it to be a separate process). Set the FP of the VI to be hidden (not closed) once it starts running and you should be fine. You can then use VI server or a custom protocol over TCP to register each instance with the server and occasionally poll to make sure the instance is still running.


___________________
Try to take over the world!
0 Kudos
Message 4 of 4
(2,454 Views)