LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running a single instance of application from network computers

Solved!
Go to solution

Hi,

I want to write an application which will be the only instance that will run. No other instance of the same application should be able to run from any computer in the network and prompted that a instance of application is already running. Any solution to this problem?

0 Kudos
Message 1 of 11
(3,338 Views)

Hi lvbms,

 

you need to find a way to detect other instances of that executable in your network.

 

Ideas:

- have the executable lock a file on your local server. Once the file is already locked, you know there is another instance running.

- have the executable contact a server. The server can respond with a "first instance?" response. You need to create such a server (maybe using LabVIEW?) somewhere in your network.

- have the executable broadcast an UDP message and wait for answers. Your executable must respond for such messages to indicate it's already running.

- …

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(3,334 Views)

@lvbms wrote:

Hi,

I want to write an application which will be the only instance that will run. No other instance of the same application should be able to run from any computer in the network and prompted that a instance of application is already running. Any solution to this problem?


I have to ask from more details, mainly why? 

 

But anyway your applications is going to have to do these things

  • Announce it is starting on launch
    • Stop and notify user if an instance is already running
  • While running
    • Listen for other instances to announce they are starting
    • Tell the new instance that an instance is already running

I guess you could listen and announce on a UDP port of your choosing as long as it's not a port something else needs.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 11
(3,299 Views)

A couple problems with any of these schemes is suppose the other instances fail to respond to a UDP request to announce themselves?

Or an instance checks itself out of a server, but fails to check itself back in when exiting.  A later instance of the application will think the first instance is still running when it tries to check itself out of the server.

0 Kudos
Message 4 of 11
(3,289 Views)

@RavensFan wrote:

A couple problems with any of these schemes is suppose the other instances fail to respond to a UDP request to announce themselves?

Or an instance checks itself out of a server, but fails to check itself back in when exiting.  A later instance of the application will think the first instance is still running when it tries to check itself out of the server.


IKR.. There are so many things that could go wrong here, a little (a lot) more information is really needed on this one, as there has to be a better way to do this.

 

I still want to know what exactly this program is doing that it can be the only program running in an entire company that is doing it?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 11
(3,284 Views)

The application works as a client and connects to a server to command it to measure. However if application fails to connect to server it remotely kill the server instance and restart the server instance again.

 

So in case of first instance of the application is connected to the server. If second instance run, I can kill the server instance and connection of first instance to server will become invalid.

0 Kudos
Message 6 of 11
(3,253 Views)

@lvbms wrote:

However if application fails to connect to server it remotely kill the server instance and restart the server instance again.


That just sounds like a horrible design.  The client has absolutely NO information on the status of server.  The server could just be busy with another client.  Just tell the user you were unable to connect and let them worry about it.  Alternatively, you could allow for multiple connections and only use the second one to tell people it is busy (and close that connection almost immediately).  The user can react accordingly.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 11
(3,247 Views)

Patient: "Doctor, it hurts when I do this"

Doctor: "Well then, stop doing that!"

 

The application works as a client and connects to a server to command it to measure. However if application fails to connect to server it remotely kill the server instance and restart the server instance again.

 

So in case of first instance of the application is connected to the server. If second instance run, I can kill the server instance and connection of first instance to server will become invalid.


 

 

-Kevin P

 

P.S.  Looks like crossrulz already gave a more complete and direct answer.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 8 of 11
(3,236 Views)
Solution
Accepted by topic author lvbms

Finally found the two approaches : 

1. Using network shared variable. Need a server where you can deploy the shared variables. 

2. Using a file opening and deny access until the application exits. Opens the file on a PC which is always required to be connected in the network i.e. measurement PC where the measurement system is connected. 


@Kevin_Price
0 Kudos
Message 9 of 11
(3,209 Views)

@lvbms wrote:

Finally found the two approaches : 

1. Using network shared variable. Need a server where you can deploy the shared variables. 

2. Using a file opening and deny access until the application exits. Opens the file on a PC which is always required to be connected in the network i.e. measurement PC where the measurement system is connected. 


@Kevin_Price

So is this all about #2?  If you use the proper File primitives when Windows Opens or Creates a file it will be locked, meaning no other program can access that file while the first program has it locked.  Actually they can but Windows will only allow it to be opened read only or open a copy of the file so others can still view the file while it is locked.

 

This file can even exist on a network, so you could write your program so it will not run if it can not open or create that file in that spacific network location.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(3,196 Views)