switch to previous instance

Post

Posted
Rating:
#1 (In Topic #846)
Trainee
 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
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
What do you mean by "instance", here ?

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
"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

Code

Shell "pgrep -f \"" & Application.Path &/ Application.Args[0] & "\"" To res

Is there a way to activate another "instance" by its process-ID? Is it handled by the XServer?
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Is there in Gambas something like VB's PrevInstance?

I don't think there is, but you can see what windows are open with the following code: -

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Dim hWindow As DesktopWindow
  4.  
  5.   Desktop.Windows.Refresh()
  6.  
  7.   For Each hWindow In Desktop.Windows
  8.     Print hWindow.VisibleName
  9.   Next
  10.  
  11.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
 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

Attachment
Online now: No Back to the top
1 guest and 0 members have just viewed this.