[Gambas-user] Avoiding multiple instances

Rolf-Werner Eilert eilert-sprachen at ...221...
Sat Feb 16 11:22:51 CET 2008


Stefano Palmeri schrieb:
> And so finally :-) , to avoid multiple instances we could do:
> 
> PUBLIC SUB Main()
> 
>   DIM sShellOutput AS String
>      
>   SHELL "pgrep -f " & Application.Args[0] TO sShellOutput
>   IF Split(Trim$(sShellOutput), "\n").Count > 1 THEN QUIT 
>              
> END
> 
> Stefano
> 


This is not multiuser-safe unfortunately. I just tested it here, and if 
the second user starts the program, it refuses to come up.

Of course it does, as this asks for the name of the program only. So I 
improved the thing by adding "-u":

SHELL "pgrep -f -u " & User.ID & " " & Application.Args[0] TO sShellOutput

Now I've got two questions for the experts:

First, my program lacks a SUB Main() but it worked within Form1_Load() 
as well. Is that ok? I ask because if started from a terminal, Gambas 
says 31 allocations not freed etc. (I am using the HighlightEditor 
example for this).

Second, maybe it's better to use "-U" instead of "-u", what is the 
difference?

Hope someone still follows this thread... :-)

Rolf




More information about the User mailing list