[Gambas-user] donot permit another instance of my program

Hans Lehmann hans at gambas-buch.de
Thu May 31 11:57:35 CEST 2018


Hello,

the given solutions both have a small hook. The 'pgrep' program is not 
installed by default on all systems. The variant with the look file runs 
empty if the program crashes at runtime and the created look file can no 
longer be deleted. The presented variant does not require much effort 
and works well to reliably prevent a second program start.

FMain.class

' Gambas class file

Public hObject As DBO ' D-Bus-Object

Public Sub _new()

   Dim sMessage As String
   DBus.Unique = True

   hObject = New DBO
   Try DBus.Session.Register(hObject, "/Export1")
   If Error Then
      sMessage = Subst("&1 '&2' &3", ("The program"), Application.Name, 
("has already been started!"))
      Message.Warning(sMessage)
      Me.Close()
   Endif

End

Public Sub Form_Open()
   FMain.Resizable = False
End

Public Sub Form_Close()
   If DBus.IsRegistered(hObject) Then DBus.Session.Unregister(hObject)
   Me.Close()
End

------------------------------------------------------------------------

DBO.class

' Gambas class file

Inherits DBusObject
Create Static

' The class can remain empty from here on...

------------------------------------------------------------------------



With kind regards

Hans
www.gambas-book.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180531/4391ac19/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gphablcjfgkgmiid.png
Type: image/png
Size: 13835 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180531/4391ac19/attachment-0001.png>


More information about the User mailing list