How to prevent running multiple instances?

Discuss any general programming issues here
Post Reply
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

How to prevent running multiple instances?

Post by fingus »

How to prevent running multiple instances of one and the same hollywood-program?

Is there something like "superglobal" variable, who is set by the first instance of a hollywood-programm and can be reached and detected by a second instance of the same hollywood-program?

I don´t like the dirty way to save something to ramdisk:T/ to know if theres still a instance running.
User avatar
airsoftsoftwair
Posts: 5443
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: How to prevent running multiple instances?

Post by airsoftsoftwair »

Hmmm, an idea would be to create a Rexx port and exit in case it is already existing. But this will only work on Amigas.
User avatar
Tuxedo
Posts: 345
Joined: Sun Feb 14, 2010 12:41 pm

Re: How to prevent running multiple instances?

Post by Tuxedo »

I use that way to test if LoView was running and what instance was running...

Whit that function I control which instance of LoView was running and manage to assing a new number to the new if another was already running(if you need to run only one instance simply modify it):

Code: Select all

Semaforo = CreateBrush(Nil, 1, 1)	; Creo il mio brush che servirà da semaforo...

IF NOT Exists("T:LoView")
	MakeDirectory("T:LoView")	; Creo la directory che conterrà i file di scambio tra le mie applicazioni...
EndIF

CheckWhile = 1
LOCAL tempwhile = 0

While CheckWhile = 1
	tempwhile = tempwhile + 1
		IF NOT Exists("T:LoView/LoView" .. tempwhile)
			NumeroProcesso = tempwhile
			SaveBrush(Semaforo, "T:LoView/LoView" .. NumeroProcesso)
			LockSemaforo = OpenFile(Nil, "T:LoView/LoView" .. NumeroProcesso)
			CheckWhile = 2
		EndIF
Wend
With the line:

Code: Select all

			LockSemaforo = OpenFile(Nil, "T:LoView/LoView" .. NumeroProcesso)
I Lock the temp file so noone can delete it accidentally while the program was running :)

On the program Exit I dlete the LoView semaphore that was relative to the quitted instance to "free" the instance.

In that way the only problem we can get was in case of crash since the semaphore wasnt freed, but with adding a check on program start if the semaphore you need to use was already locked(if wasnt locked you can simply deletre it) you an easly do the task...

Just use a dit different from T: (a temp in program dir was fine), et voilà :)
Simone"Tuxedo"Monsignori, Perugia, ITALY.
User avatar
fingus
Posts: 269
Joined: Fri Sep 16, 2011 9:53 am

Re: How to prevent running multiple instances?

Post by fingus »

thanks for the hints!
Post Reply