Page 1 of 2

How to prevent running multiple instances?

Posted: Sun Mar 11, 2018 4:18 pm
by sashapont
Are there any multyplatform solution n to prevent running multiple instances of app?

Re: How to prevent running multiple instances?

Posted: Sun Mar 11, 2018 10:00 pm
by airsoftsoftwair
Call CreatePort() to create a message port. If it fails, the port is already there and the app is already running.

Re: How to prevent running multiple instances?

Posted: Mon Mar 12, 2018 6:38 pm
by sashapont
Can you give any example?

I try to copy example from doc

Code: Select all

Function p_EventFunc(msg)
  Switch msg.action
  Case "OnUserMessage"
    Switch msg.command
    Case "EXIT"
      DebugPrint("Exit received! Quitting now.")
      End
    Default
      Local t = SplitStr(msg.args, "\0")
      DebugPrint(msg.command, "called with", msg.argc, "argument(s)")
      For Local k = 1 To msg.argc
         DebugPrint("Argument", k .. ":", t[k - 1])
      Next
    EndSwitch
  EndSwitch
EndFunction
CreatePort("MY_COOL_PORT_123")
InstallEventHandler({OnUserMessage = p_EventFunc})
Repeat
  WaitEvent
Forever
And have error
Could not create message port!

Re: How to prevent running multiple instances?

Posted: Tue Mar 13, 2018 7:02 am
by PEB
CreatePort() will fail if your program is using RapaGUI.

viewtopic.php?f=4&t=1844

Re: How to prevent running multiple instances?

Posted: Tue Mar 13, 2018 4:35 pm
by sashapont
no it is not use it&
I use only sql and zip plugins

Re: How to prevent running multiple instances?

Posted: Wed Mar 14, 2018 8:29 pm
by PEB
So just put something like this toward the top of your code (before you open the display):

Code: Select all

Local var=?CreatePort("MY_PORT")
If var<>0 Then End()

Re: How to prevent running multiple instances?

Posted: Fri Mar 16, 2018 9:49 am
by sashapont
Is not work.
App close before starting :(

Debugprint("My var"..var)
out 1256

Is it same number for all os?

Re: How to prevent running multiple instances?

Posted: Fri Mar 16, 2018 11:41 pm
by airsoftsoftwair
Are you on Mac OS or Linux? CreatePort() currently only works on Amiga and Windows.

Re: How to prevent running multiple instances?

Posted: Sat Mar 17, 2018 9:08 am
by sashapont
on Mac :(
Are there solution for this os?

Re: How to prevent running multiple instances?

Posted: Sat Mar 17, 2018 3:54 pm
by airsoftsoftwair
Maybe set the "LSMultipleInstancesProhibited" switch to FALSE in the Info.plist of the app bundle?