Page 1 of 1
Application Copies Running Simultaneously
Posted: Tue Oct 02, 2007 4:54 am
by andres
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
Posted: Tue Oct 02, 2007 7:40 am
by Mark
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
Posted: Fri Oct 05, 2007 4:30 am
by andres
Thanks Mark
Relaunch only works on Windows.
Do you know a way to implement it in Mac OS X ?
Regards,
Andres
Posted: Fri Oct 05, 2007 8:34 am
by Mark
Andres,
AFAIK this problem doesn't exist on Mac OS X (unless you run standalones as GUI-less shell commands).
Best,
Mark
Posted: Fri Oct 05, 2007 2:03 pm
by andres
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
Posted: Fri Oct 05, 2007 2:21 pm
by Mark
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:
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
Posted: Fri Oct 05, 2007 2:41 pm
by andres
Thanks Mark
I used the PS shell command for OSX.
Now, how can I prevent a duplicated application from running on Windows?
Regards,
Andres
Posted: Fri Oct 05, 2007 7:41 pm
by Mark
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
Posted: Fri Oct 05, 2007 7:45 pm
by andres
Thanks much Mark
Andres
Posted: Thu Oct 11, 2007 6:31 pm
by TonyL
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