How to prevent running multiple instances?

Discuss any general programming issues here
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

How to prevent running multiple instances?

Post by sashapont »

Are there any multyplatform solution n to prevent running multiple instances of app?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to prevent running multiple instances?

Post by airsoftsoftwair »

Call CreatePort() to create a message port. If it fails, the port is already there and the app is already running.
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: How to prevent running multiple instances?

Post 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!
PEB
Posts: 567
Joined: Sun Feb 21, 2010 1:28 am

Re: How to prevent running multiple instances?

Post by PEB »

CreatePort() will fail if your program is using RapaGUI.

viewtopic.php?f=4&t=1844
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: How to prevent running multiple instances?

Post by sashapont »

no it is not use it&
I use only sql and zip plugins
PEB
Posts: 567
Joined: Sun Feb 21, 2010 1:28 am

Re: How to prevent running multiple instances?

Post 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()
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: How to prevent running multiple instances?

Post by sashapont »

Is not work.
App close before starting :(

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

Is it same number for all os?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to prevent running multiple instances?

Post by airsoftsoftwair »

Are you on Mac OS or Linux? CreatePort() currently only works on Amiga and Windows.
sashapont
Posts: 152
Joined: Thu Aug 03, 2017 2:49 pm

Re: How to prevent running multiple instances?

Post by sashapont »

on Mac :(
Are there solution for this os?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to prevent running multiple instances?

Post by airsoftsoftwair »

Maybe set the "LSMultipleInstancesProhibited" switch to FALSE in the Info.plist of the app bundle?
Post Reply