Hi there - I have a question.
When I run my app, it’s quite huge and goes through a online database check for the licenses.
Often the user will click on the app again if it doesn’t run right away.
Is there a way to make sure that the app doesn’t open more than 1 instance?
What platform do you use? I’ve found it necessary even on the Mac side to use mutexes - check out the documentation for them.
If there’s a delay like that, how about putting up a loading screen so the end user at least knows it’s loading and doesn’t try launching it multiple times…
When I do that with Xojo IDE, I get a crash… on Windows 8.1.
I suppose you could use a Mutex to stop multiple instances of the app. Check the docs for how it works. (I’d post a sample but I’m not at my own system right now.)
I’m not keen on mutexes; if the app crashes then you won’t be able to start it again till you restart the machine.
On Windows, you can check for the process already running, thus:
dim s as shell = new Shell
s.Execute("tasklist /fo CSV")
dim theString as string = s.Result
dim theStringArray() as string
theStringArray = split(theString, """MyAppName.exe""")
if theStringArray.Ubound>1 then // There's more than one instance in the list of processes that are running
msgBox("Sorry, a copy of this application is already running.")
and put that in your App.Open event.
You can’t run two copies of the same app on a Mac (that’s how Macs work) so I guess you’re working on Windows…
That code worked brilliantly! I got rid of the MsgBox as that’s in practical terms was a bit redundant!
Thanks for your help!!!
My software is Guitar SightReader Toolbox if you want to see it in action!
not quite true… however the user can’t double click the app twice to load two copies… However you can spawn a new copy of your executable, although if it’s Sandboxed the OS will make it crash.