[Gambas-user] "mutex" applications

Rolf-Werner Eilert eilert-sprachen at ...221...
Wed Jun 6 12:38:54 CEST 2012


Am 06.06.2012 11:18, schrieb Bruce:
> I have been mucking around with this for about a year now and haven't
> found a solution.
>
> We have a few gambas applications that are treated as pop-ups by the
> users.  That is, they click on some type of launcher (be it a desktop
> item, a menu item or in our case a wbar icon) and the application
> starts.
> Then they minimize it, or go to another desktop, or any other way to
> hide the application window.
> Then they relaunch it...
>
> ... and get another instance running.
>
> However, sort of like things like Evolution, we only want to have one
> copy of these applications running.  So we need some sort of "mutex"
> checker that ensures that they can only run one instance of the
> application.
>
> So far, I have found that I can use gb.desktop to detect another
> instance via the window title and just exit gracefully with a "Another
> instance of xxxxxxxxxxx is running" message.
>
> Blah!
>
> That doesn't really do what I want.  What I want (what I really, really
> want) is a way to activate the window found and then exit.
>
> Any clues?
>
> regards
> Bruce

Hi Bruce,

I have successfully used this code which is from Jussi Lahtinen. I built 
it into two of my applications, and it works reliably, at least under 
Gambas2 on our somewhat older system:

PUBLIC SUB Form_Open()
DIM sOutput AS String

   EXEC ["pgrep", "-f", "-l", "-u", System.User.Name, "Stein3.gambas"] 
WAIT TO sOutput

   IF Split(Trim$(sOutput), gb.NewLine).Count > 1 THEN
     QUIT
   ENDIF

Just replace "Stein3" by your binary's name.

Regards

Rolf




More information about the User mailing list