Xojo Conferences
XDCMay2019MiamiUSA

Multiple app instances (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: cursor types
Next thread: Richer RBScript options (was Re: Why is object passing across RBScript context, not safe?)


Win32 API Declares   -   Berg, Heath
  Multiple app instances   -   Mario Buchichio
   Re: Multiple app instances   -   Steve Roy
   Re: Multiple app instances   -   Brian Rathbone
   Re: Multiple app instances   -   Norman Palardy
   Re: Multiple app instances   -   Aaron Ballman
   Re: Multiple app instances   -   Norman Palardy
   Re: Multiple app instances   -   Aaron Ballman
   Re: Multiple app instances   -   Norman Palardy
   Re: Multiple app instances   -   Karen
   Re: Multiple app instances   -   Aaron Ballman
   Re: Multiple app instances   -   Aaron Ballman
    Re: Multiple app instances   -   jkohns
     Re: Multiple app instances   -   Mario Buchichio

Multiple app instances
Date: 30.01.05 13:08 (Sun, 30 Jan 2005 09:08:56 -0300)
From: Mario Buchichio
Hi list

Could't find any info in this matter:
How do I avoid launching another instance of my app when opening a
document from the desktop?
My app is already running and when I double click a document to be
opened by my app another instance is launched?

Thanks

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 30.01.05 15:02 (Sun, 30 Jan 2005 09:02:13 -0500)
From: Steve Roy
On Jan 30, 2005, at 7:08 AM, Mario Buchichio wrote:

> Could't find any info in this matter:
> How do I avoid launching another instance of my app when opening a
> document from the desktop?
> My app is already running and when I double click a document to be
> opened by my app another instance is launched?

You're supposed to use an IPCSocket for that, but in my own tests it
wasn't always working so I implemented my own scheme with a plain
TCPSocket.

The general idea is that your running application has a server socket
opened and listens for incoming data. When it launches, it should try
to make a connection. If it's unsuccessful then it knows there are no
other instances running and it can set up the server socket. However if
it can connect, then the app can pass its command line to the first
instance and just quit.

Steve

Re: Multiple app instances
Date: 30.01.05 16:04 (Sun, 30 Jan 2005 10:04:00 -0500)
From: Brian Rathbone
> My app is already running and when I double click a document to be
> opened by my app another instance is launched?

On Windows, you can use a mutex. The Windows Functionality Suite has
example code for this.

hth,

Brian

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 30.01.05 20:44 (Sun, 30 Jan 2005 12:44:12 -0700)
From: Norman Palardy

On Jan 30, 2005, at 5:08 AM, Mario Buchichio wrote:

> Hi list
>
> Could't find any info in this matter:
> How do I avoid launching another instance of my app when opening a
> document from the desktop?
> My app is already running and when I double click a document to be
> opened by my app another instance is launched?
>
Is this on Windows ?

The Mac's default is to not ever do this anyways.

On Windows you use a mutex (see the Windows Functionality Library) to
detect that a mutex already exists (basically a flag saying "I'm
already running") and then hand it off to the other instance (that I'm
not sure how you do ....)

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 30.01.05 20:48 (Sun, 30 Jan 2005 13:48:12 -0600)
From: Aaron Ballman
> On Windows you use a mutex (see the Windows Functionality Library) to
> detect that a mutex already exists (basically a flag saying "I'm
> already running") and then hand it off to the other instance (that I'm
> not sure how you do ....)

Sorta. You make a named mutex which is a system-wide object that any
application can access. You then obtain the mutex (much the same way
you would Enter a critical section or Signal a semaphore). If you
aren't able to obtain a lock on the mutex, then you know some other
instance of your application is running on the same machine. There's
no hand-off involved -- it's just another type of locking mechanism.

And yes, the Windows Functionality Suite does have an OS mutex class in
there, as well as example code on how to do exactly what you're looking
for.

HTH!

~Aaron

Re: Multiple app instances
Date: 30.01.05 20:55 (Sun, 30 Jan 2005 12:55:06 -0700)
From: Norman Palardy

On Jan 30, 2005, at 12:48 PM, Aaron Ballman wrote:

>> On Windows you use a mutex (see the Windows Functionality Library) to
>> detect that a mutex already exists (basically a flag saying "I'm
>> already running") and then hand it off to the other instance (that
>> I'm not sure how you do ....)
>
> Sorta. You make a named mutex which is a system-wide object that any
> application can access. You then obtain the mutex (much the same way
> you would Enter a critical section or Signal a semaphore). If you
> aren't able to obtain a lock on the mutex, then you know some other
> instance of your application is running on the same machine. There's
> no hand-off involved -- it's just another type of locking mechanism.
>

OK ...
Suppose that an instance of this app is already running and a second
instance is started to open another document.
If there's no hand off to get the first running instance to open that
document that the the new second instance should have the second simply
dies when it sees that there is already one running and the document is
not opened.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 30.01.05 20:58 (Sun, 30 Jan 2005 13:58:28 -0600)
From: Aaron Ballman
>> Sorta. You make a named mutex which is a system-wide object that any
>> application can access. You then obtain the mutex (much the same way
>> you would Enter a critical section or Signal a semaphore). If you
>> aren't able to obtain a lock on the mutex, then you know some other
>> instance of your application is running on the same machine. There's
>> no hand-off involved -- it's just another type of locking mechanism.
>>
> OK ...
> Suppose that an instance of this app is already running and a second
> instance is started to open another document.
> If there's no hand off to get the first running instance to open that
> document that the the new second instance should have the second
> simply dies when it sees that there is already one running and the
> document is not opened.

Mutexes have next-to-nothing to do with the above scenario (aside from
the obvious detection of the second application running).

If you want to handle the above situation, then you should use an
IPCSocket to tell the other application which document to open (though
any communication mechanism will work, such as TCPSocket, AppleEvents
[on the Mac, obviously] or even UDPSockets).

HTH!

~Aaron

Re: Multiple app instances
Date: 30.01.05 21:05 (Sun, 30 Jan 2005 13:05:36 -0700)
From: Norman Palardy

On Jan 30, 2005, at 12:58 PM, Aaron Ballman wrote:

>>> Sorta. You make a named mutex which is a system-wide object that
>>> any application can access. You then obtain the mutex (much the
>>> same way you would Enter a critical section or Signal a semaphore).
>>> If you aren't able to obtain a lock on the mutex, then you know some
>>> other instance of your application is running on the same machine.
>>> There's no hand-off involved -- it's just another type of locking
>>> mechanism.
>>>
>> OK ...
>> Suppose that an instance of this app is already running and a second
>> instance is started to open another document.
>> If there's no hand off to get the first running instance to open that
>> document that the the new second instance should have the second
>> simply dies when it sees that there is already one running and the
>> document is not opened.
>
> Mutexes have next-to-nothing to do with the above scenario (aside from
> the obvious detection of the second application running).
>
> If you want to handle the above situation, then you should use an
> IPCSocket to tell the other application which document to open (though
> any communication mechanism will work, such as TCPSocket, AppleEvents
> [on the Mac, obviously] or even UDPSockets).

Right ... that's why I originally said use a mutex to detect that an
instance is already running "and then hand it off to the other instance
(that I'm not sure how you do ....)"

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 30.01.05 21:09 (Sun, 30 Jan 2005 15:09:48 -0500)
From: Karen

On Jan 30, 2005, at 2:58 PM, Aaron Ballman wrote:

>> OK ...
>> Suppose that an instance of this app is already running and a second
>> instance is started to open another document.
>> If there's no hand off to get the first running instance to open that
>> document that the the new second instance should have the second
>> simply dies when it sees that there is already one running and the
>> document is not opened.
>
> Mutexes have next-to-nothing to do with the above scenario (aside from
> the obvious detection of the second application running).
>

For a good UI as far as i can see even if the user double clicsk on the
app icon, you would want the new instance to activate the existing one
somehow or send a message to the pre-existing instance to activate
itself...

Thus it would be rare indeed to want only to use a mutex detect the
existing instance and then just quit and not be concerned with the
existing instance in some way, no?

- Karen

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 30.01.05 21:09 (Sun, 30 Jan 2005 14:09:58 -0600)
From: Aaron Ballman
> Right ... that's why I originally said use a mutex to detect that an
> instance is already running "and then hand it off to the other
> instance (that I'm not sure how you do ....)"

I should slow down when reading. ;-) I read your original post wrong.
Sorry about that, and thanks for clearing it up!

~Aaron

Re: Multiple app instances
Date: 30.01.05 21:12 (Sun, 30 Jan 2005 14:12:41 -0600)
From: Aaron Ballman
> Thus it would be rare indeed to want only to use a mutex detect the
> existing instance and then just quit and not be concerned with the
> existing instance in some way, no?

That depends on what your application does. For example, if your
application is meant to be a service, then there's nothing to bring to
the front. And if your application isn't document-based, then there's
nothing to open.

But there certainly are plenty of cases where you would want to cause
the other application to do something sensible, in which case you
should use something like an IPCSocket to cause the action to happen.

HTH!

~Aaron

Re: Multiple app instances
Date: 31.01.05 16:16 (Mon, 31 Jan 2005 15:16:36 +0000)
From: jkohns
To simplify things, I've put together a module w/ Windows mutex functions online for anyone wishing to implement this behavior...

http://www.callerid.com/?page=realbasic

Just add it to your project, and call the CreateMutex function in the Open event of your App. The module also has a function to bring focus to the already running version of the app if it exists.

Hope this helps.

-------Original Message-------
> From: Mario Buchichio <<email address removed>>
> Subject: Multiple app instances
> Sent: 30 Jan 2005 12:08:56
>
> Hi list
>
> Could't find any info in this matter:
> How do I avoid launching another instance of my app when opening a
> document from the desktop?
> My app is already running and when I double click a document to be
> opened by my app another instance is launched?
>
> Thanks
>
> _______________________________________________
> Unsubscribe or switch delivery mode:
> <http://www.realsoftware.com/support/listmanager/>
>
> Search the archives of this list here:
> <http://support.realsoftware.com/listarchives/lists.html>
-------Original Message-------

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Multiple app instances
Date: 03.02.05 03:36 (Wed, 02 Feb 2005 23:36:44 -0300)
From: Mario Buchichio
Sweeet!

Tanks!

jkohns escribió:

>To simplify things, I've put together a module w/ Windows mutex functions online for anyone wishing to implement this behavior...
>
>http://www.callerid.com/?page=realbasic
>
>Just add it to your project, and call the CreateMutex function in the Open event of your App. The module also has a function to bring focus to the already running version of the app if it exists.
>
>Hope this helps.
>
>
>

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>