Application Copies Running Simultaneously

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andres
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 68
Joined: Thu Jan 04, 2007 2:24 am

Application Copies Running Simultaneously

Post by andres » Tue Oct 02, 2007 4:54 am

Hello

Is it possible to limit the number of times an application can run simultaneously on the same computer?

I mean, if I duplicate my compiled application I can run both copies (original and copy) at the same time. Is it possible to avoid duplicated applications from running simultaneously?

Thanks
Andres

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Oct 02, 2007 7:40 am

Hi Andres,

If you have Revolution 2.7.3 or later, you can invoke the relaunch message on Windows.

"Upon launching a Revolution application with such a 'relaunch' handler, the
engine searches for a unique token to see if it is already running. If it
is, the new instance sends a 'relaunch' message to the existing instance.
The existing instance can do the following with this message:
1) If it is passed, then the new instance continues running.
2) If "background" is returned, then the new instance is terminated.
3) If nothing is returned but the message is not passed, then the new
instance is terminated and the existing instances 'defaultStack' is made
the foreground window." (from the file Whats_New.txt).

To find out how this works exactly, read the change log for Rev 2.7.3 in Whats_New.txt. Search for "relaunch".

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

andres
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 68
Joined: Thu Jan 04, 2007 2:24 am

Post by andres » Fri Oct 05, 2007 4:30 am

Thanks Mark

Relaunch only works on Windows.

Do you know a way to implement it in Mac OS X ?

Regards,
Andres

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 05, 2007 8:34 am

Andres,

AFAIK this problem doesn't exist on Mac OS X (unless you run standalones as GUI-less shell commands).

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

andres
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 68
Joined: Thu Jan 04, 2007 2:24 am

Post by andres » Fri Oct 05, 2007 2:03 pm

Hello Mark

All standalones I have made for OS X can run multiple times on the same computer.

I don't know if you can try it, but get one, duplicated it (either while running or not) and try to run both. You will see that each one runs as a separate application.

Am I missing something at the compilation settings?

I found a way to quit a second instance by using a shell command, but it is not the best way to do it.

Regards,
Andres

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 05, 2007 2:21 pm

Hi Andres,

I understand what you mean now. This is normal. Why would you want to change it? If necessary, just put into the Read Me file: "Do not try to run duplicate copies of this application."

On Windows, the problem is a real one, because applications can run twice, even if there is only one copy.

On Mac OS X, this gives you a complete list of processes:

Code: Select all

put shell("ps ux -a -c -w -w")
You can have the new instance of the programme check whether an older instance is running already, using the output from above shell function. If an older instance is running already, simply quit the new instance. No need for (slow) AppleScript.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

andres
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 68
Joined: Thu Jan 04, 2007 2:24 am

Post by andres » Fri Oct 05, 2007 2:41 pm

Thanks Mark

I used the PS shell command for OSX.

Now, how can I prevent a duplicated application from running on Windows?

Regards,
Andres

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Fri Oct 05, 2007 7:41 pm

Andres,

shell("tasklist") will give you a list of processes on Windows XP and possibly on Vista. I don't know on which other Windows versions this might work, it definitely doesn't work on Win 95.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

andres
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 68
Joined: Thu Jan 04, 2007 2:24 am

Post by andres » Fri Oct 05, 2007 7:45 pm

Thanks much Mark

Andres

TonyL
Posts: 24
Joined: Mon Aug 07, 2006 1:15 am
Location: NJ USA

Post by TonyL » Thu Oct 11, 2007 6:31 pm

You could have a txt file in your program default folder that keeps track of the number of times your application was launched. Then code in your pre-open stack handler to read the txt file and exit the application if another instance is already running.

Tony

Post Reply

Return to “Talking LiveCode”