[Gambas-user] Avoiding multiple instances
Leonardo Miliani
leonardo at ...1237...
Thu Jan 31 16:25:25 CET 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
>
>
> -------------------------------------------------------------------------
> 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
>
In fact, for my personal app, I also created a Recovery tool (just a
simple script) that deletes the hidden file and starts again my app. :-)
But it's the only easy way I found to check if my app is still running.
--
Ciao.
Leo.
Web: www.leonardomiliani.com
E-mail: leonardo at ...1237...
Co-fondatore di Gambas-it.org: www.gambas-it.org
(il sito italiano dedicato alla comunità di Gambas)
Scegli software opensource - Choose opensource software
More information about the User
mailing list