Hi,
when starting the app I would like to switch to a previous instance, if existing.
Is there in Gambas something like VB's PrevInstance?
Thanks
switch to previous instance
Re: switch to previous instance
What do you mean by "instance", here ?
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
Re: switch to previous instance
"Instance" means, when starting an app three times then there are three "instances" of the app.
I think I can get process-IDs of all "instances" of my app with sth. like
Is there a way to activate another "instance" by its process-ID? Is it handled by the XServer?
I think I can get process-IDs of all "instances" of my app with sth. like
Code: Select all
Shell "pgrep -f \"" & Application.Path &/ Application.Args[0] & "\"" To res
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: switch to previous instance
I don't think there is, but you can see what windows are open with the following code: -Is there in Gambas something like VB's PrevInstance?
Public Sub Form_Open()
Dim hWindow As DesktopWindow
Desktop.Windows.Refresh()
For Each hWindow In Desktop.Windows
Print hWindow.VisibleName
Next
End
- BruceSteers
- Posts: 1608
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: switch to previous instance
i have a routine for this sort of thing using DBus, i call it single instance.
when app is run it creates a DBus interface and sets the DBus.Unique property.
if app is run again it cannot create the DBus interface so it knows to send the args/command to the first instance via DBus message and exit.
Any number of commands can be added to the DBus interface, like an Activate() method if you just want to activate first instance. (check out DBusComm.class and SingleInstance.class to see how i added the ArgAdded() command)
You can test the app by running it, then running it again while it's loaded with arguments.
any supplied arguments will be sent to the first instance.
All the best
when app is run it creates a DBus interface and sets the DBus.Unique property.
if app is run again it cannot create the DBus interface so it knows to send the args/command to the first instance via DBus message and exit.
Any number of commands can be added to the DBus interface, like an Activate() method if you just want to activate first instance. (check out DBusComm.class and SingleInstance.class to see how i added the ArgAdded() command)
You can test the app by running it, then running it again while it's loaded with arguments.
any supplied arguments will be sent to the first instance.
All the best
- Attachments
-
- SingleBus-0.0.102.tar.gz
- (13.68 KiB) Downloaded 182 times
If at first you don't succeed , try doing something differently.
BruceS
BruceS