[Gambas-user] donot permit another instance of my program
Jussi Lahtinen
jussi.lahtinen at gmail.com
Wed May 30 23:38:47 CEST 2018
This problem has nothing to do with multi-threading of Gambas.
Anyway, you can solve your problem this way:
When your program starts, check if there is "lock" file written.
No --> Write a file with the programs pid number on it.
Yes --> Check if there exist program with the given pid number.
No --> Replace the pid number of the current instance.
Yes --> Exit.
This way you can ensure there is only one instance at the time. However, if
this should apply per system (instead of per user), you need to write the
lock file with root permissions.
And thus in that case, it may not be good solution.
This is also one solution, which I use:
Exec ["pgrep", "-fl", "YourProgram.gambas"] Wait To sOutput
If Split(Trim$(sOutput), gb.NewLine).Count > 1 Then
Message.Error("Only one instance allowed!")
Quit
Endif
Jussi
On Wed, May 30, 2018 at 9:37 PM, PICCORO McKAY Lenz <mckaygerhard at gmail.com>
wrote:
> ok taking in consideration that gambas its not multi-thread
>
> how can i avoid second instance of my program..
>
> in another case, how can i take care of that, if i manage settings file?
>
> seems if the file are access by two instacens a lock may cause corruption
> of data
>
> a good example would be great
>
>
> Lenz McKAY Gerardo (PICCORO)
> http://qgqlochekone.blogspot.com
>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180531/dc341741/attachment.html>
More information about the User
mailing list