Page 1 of 1

How to prevent running multiple instances?

Posted: Fri Oct 07, 2011 10:32 am
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.

Re: How to prevent running multiple instances?

Posted: Fri Oct 07, 2011 11:46 pm
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.

Re: How to prevent running multiple instances?

Posted: Sat Oct 08, 2011 3:14 pm
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à :)

Re: How to prevent running multiple instances?

Posted: Mon Oct 10, 2011 4:23 pm
by fingus
thanks for the hints!