Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to allow only one program instance

86 views
Skip to first unread message

Florian Dietz

unread,
Oct 15, 2012, 8:16:46 AM10/15/12
to
Hi,

as the title says, how can I make sure only one instance of my program can be open at any time? Is there a clean, default way to do this?

Tobias Höppner

unread,
Oct 15, 2012, 10:04:03 AM10/15/12
to
Hi,

there is an once-only macro the alexandria package. i don't know if it
can fit your needs but it's worth considering.

Greets
Tobias

Barry Margolin

unread,
Oct 15, 2012, 10:39:39 AM10/15/12
to
In article <k5h54j$v3$1...@gazette.hrz.tu-chemnitz.de>,
Tobias Höppner <tobias....@googlemail.com> wrote:

> Hi,
>
> there is an once-only macro the alexandria package. i don't know if it
> can fit your needs but it's worth considering.

It's so unrelated to this question it's not even funny. It's for macros
to use to ensure that they only evaluate a subexpression once, even
though they substitute it into the result in multiple places.

>
> On 10/15/2012 02:16 PM, Florian Dietz wrote:
> > Hi,
> >
> > as the title says, how can I make sure only one instance of my program can
> > be open at any time? Is there a clean, default way to do this?
> >

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Kaz Kylheku

unread,
Oct 15, 2012, 11:33:50 AM10/15/12
to
The best ways to do this are quite platform-specific.

On Windows, this is done by creating some named object, like say a named mutex
via the CreateMutex WIN32 function. CreateMutex sets the error code to
ERROR_ALREADY_EXISTS. Such objects go away when the last process loses
the reference, so you don't have to worry that it will stick around and
prevent your program from coming up.

Programs that have a window (either a visible one, or just a hidden one for
receiving messages) can just look for that window by enumerating all the
windows and recognizing theirs. If the program is already running, then you
post a special message to its window and quit. The program responds to the
message in some way, like by coming to the foreground, or opening a new
document window, simulating a second instance that is really managed by the
single instance.

Florian Dietz

unread,
Oct 15, 2012, 12:06:54 PM10/15/12
to
Am Montag, 15. Oktober 2012 17:33:54 UTC+2 schrieb Kaz Kylheku:
> On 2012-10-15, Florian Dietz <florian...@googlemail.com> wrote:
>
> > Hi,
>
> >
>
> > as the title says, how can I make sure only one instance of my program can be
>
> > open at any time? Is there a clean, default way to do this?
>
>
>
> The best ways to do this are quite platform-specific.
>
>
>
> On Windows, this is done by creating some named object, like say a named mutex
>
> via the CreateMutex WIN32 function. CreateMutex sets the error code to
>
> ERROR_ALREADY_EXISTS. Such objects go away when the last process loses
>
> the reference, so you don't have to worry that it will stick around and
>
> prevent your program from coming up.


That would be perfect, especially since it is identical to what I do in c# to solve the same problem. Unfortunately this is what I tried first, but I couldn't find anything on google, so I assumed it didn't work this way. Are you sure it is possible? I use Clozure on Windows, and I can't find the option, either in the documentation or via google.

Tobias Höppner

unread,
Oct 16, 2012, 4:45:38 AM10/16/12
to
Sorry,

i totally misinterpreted the question and the documentation in the package.

greets

On 10/15/2012 04:39 PM, Barry Margolin wrote:
> In article <k5h54j$v3$1...@gazette.hrz.tu-chemnitz.de>,
0 new messages