[Gambas-user] Avoiding multiple instances
Stefano Palmeri
rospolosco at ...152...
Thu Jan 31 16:45:03 CET 2008
Alle 16:19, giovedì 31 gennaio 2008, Rolf-Werner Eilert ha scritto:
> Leonardo Miliani schrieb:
> > Jeffrey Cobb ha scritto:
> >> I've made a small toolbar app to run in fluxbox. I've included the
> >> binary in my xinitrc file. But I'd like to know how I can avoid
> >> multiple instances of the same app running. How does a gambas program
> >> detect another copy of itself running?
> >>
> >> Jeff
> >>
> >>
> >>
> >> ------------------------------------------------------------------------
> >>- This SF.net email is sponsored by: Microsoft
> >> Defy all challenges. Microsoft(R) Visual Studio 2008.
> >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> >> _______________________________________________
> >> Gambas-user mailing list
> >> Gambas-user at lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> > I can suggest you how I solved this problem.
> > When an application of mine starts, it creates a file just by executing
> > this code:
> >
> > PRIVATE FUNCTION Check_If_Running() AS Boolean
> > DIM TempString AS String
> > DIM hFile AS File
> > TempString = Application.Path & "/.running"
> > IF Exist(TempString) THEN
> > Message.Warning("No multiple instances allowed")
> > RETURN TRUE
> > END IF
> > hFile = OPEN TempString FOR CREATE
> > CLOSE #hFile
> > RETURN FALSE
> > END
> >
> > The first time that the app starts it creates an empty hidden file and
> > it returns FALSE because it didn't find another instance running.
> > The second time that you call the function you'll get TRUE because the
> > program is running (it created the check file).
> > Just by checking its existance you can know if another instance of the
> > program is running.
> >
> > Of course, when you close the app, you have to delete it:
> >
> > PUBLIC SUB Form_Close()
> >
> > IF Exist(Application.Path & "/.running") THEN
> > KILL Application.Path & "/.running"
> > END IF
> >
> > END
>
> Indeed, that is the problem with this solution: if the app crashes, it
> will prevent itself from being restarted until the user manually deletes
> the hidden file. I didn't find a good way out of this yet :-)
>
> Rolf
>
I use this simple code:
PUBLIC SUB Main()
DIM sShellOutput AS String
SHELL "ps aux | grep " & Application.Name & ".gambas" & " | grep -v grep" TO
sShellOutput
IF sShellOutput THEN QUIT
END
Stefano
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
More information about the User
mailing list