SingleInstanceChecker: Find window

Doug Anderson doug at vitamindinc.com
Mon Nov 12 13:54:28 PST 2007


Steven,

I ended up asking nearly the same question a few months ago.  Search  
the archives for "Having a single instance and forwarding document  
open requests".  Overall summary:

* I ended up using single instance checker for the main solution.  If  
I found that I was the first instance, I would fork off a thread that  
would listen for messages from other instances.  If I found that I  
wasn't the first instance, I'd post a message then quit.

* The method of communication is tricky.  I think the suggestion I  
liked best was to use a TCP socket on localhost.  Picking the port  
number is difficult (especially on multi-user systems), but people  
suggested having the server pick a port number randomly then store  
the port number in a disk file.  I ended up communicating solely with  
the filesystem: having a special directory which I created "message"  
files.  Ugly, but effective and relatively secure.


I may be able to get permission to release the code under python  
license, if people are interested.

-Doug

---

On Nov 12, 2007, at 12:03 AM, Steven Van Ingelgem wrote:

> Thanks for the hint Evan, but for that you need to have dbus (I just
> checked the sources). So it's not generic (it probably works on Linux,
> but the question is if it also works on Mac and Windows). The most
> generic implementation of a SingleInstanceChecker is the one in
> wxWidgets, but I want a little more (also generic) namely to activate
> & raise the other instance.
>
> This I could easily do with a wxServer, but on Linux/Mac that would
> require opening a TCP port just to let them communicate. Not all that
> much of a problem, but I prefer to send the "old" program just some
> message (like in windows: SEND_MESSAGE) and quit the "new" program
>
>
> Thanks if you know any other programs out there which does exactly  
> this.
>
>
> On 11/12/07, Evan Charlton <usenet at evancharlton.com> wrote:
>>
>> Richard wrote:
>>> [Please do not mail me a copy of your followup]
>>>
>>> steven at vaningelgem.be ("Steven Van Ingelgem") spake the secret code
>>> <5862ce3f0711111315g431b66cbiccdc9a1068b47894 at mail.gmail.com>  
>>> thusly:
>>>
>>>> But isn't there any generic way to do this?
>>>
>>> In Windows, you generally identify another instance running by
>>> creating a named mutex.  If the named mutex already exists, then an
>>> instance of your application is already running.
>>>
>>> I've not personally seen any X window system based applications that
>>> attempt to do this; you could probably do it through creating an  
>>> ATOM
>>> though.
>>>
>>> I don't know what you'd do on a Mac.
>>
>> I believe the latest releases of Pidgin do this on all platforms. See
>> version 2.1.0 release notes: http://developer.pidgin.im/wiki/ 
>> ChangeLog
>>
>> Evan Charlton
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
>> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20071112/ae203e82/attachment.htm


More information about the wx-users mailing list