Discussion:
a message for multiple instances of application?
(too old to reply)
anealc
2010-04-21 01:41:02 UTC
Permalink
Hi there,
I am creating an application which is only allowed to run on Windows once.
If the
user attempts to invoke a second instance this second instance shows a
message to the effect that the program is already running, before switching
to the original instance.

My question is that is there a Microsoft standard for this behaviour? The
only Microsoft app that I can think of that does this is Media Centre, but
that doesn't show any message.
Thanks
Aneal
DClyde
2010-04-21 04:33:01 UTC
Permalink
I don't know about a Microsoft standard for such a thing but I have recently
looked up the same thing and found the following approach:

http://bcbjournal.org/articles/vol2/9801/Use_a_mutex_to_achieve_synchronization.htm?PHPSESSID=e8642e0bafe4d3f3a5ec34191bccaa71

Basically you use a uniquely named Mutex, upon app initialization you check
to see if the mutex is already created, and if it is then you know an
instance of that app is already running.

At that point you can throw up a message. As for then switching to the
original instance I have no idea. One may be able to have some shared memory
between the apps protected by said mutex that stores any information needed
to know about the other app and hence having the info needed to activate the
window for the other app?
Post by anealc
Hi there,
I am creating an application which is only allowed to run on Windows once.
If the
user attempts to invoke a second instance this second instance shows a
message to the effect that the program is already running, before switching
to the original instance.
My question is that is there a Microsoft standard for this behaviour? The
only Microsoft app that I can think of that does this is Media Centre, but
that doesn't show any message.
Thanks
Aneal
r***@pen_fact.com
2010-04-21 20:20:38 UTC
Permalink
On Tue, 20 Apr 2010 21:33:01 -0700, DClyde
Post by DClyde
I don't know about a Microsoft standard for such a thing but I have recently
http://bcbjournal.org/articles/vol2/9801/Use_a_mutex_to_achieve_synchronization.htm?PHPSESSID=e8642e0bafe4d3f3a5ec34191bccaa71
Basically you use a uniquely named Mutex, upon app initialization you check
to see if the mutex is already created, and if it is then you know an
instance of that app is already running.
At that point you can throw up a message. As for then switching to the
original instance I have no idea. One may be able to have some shared memory
between the apps protected by said mutex that stores any information needed
to know about the other app and hence having the info needed to activate the
window for the other app?
Common method is to use FindWindow, ShowWindow, and
SetForegroundWindow to find and show the previous instance, and then
exit (the second instance). To reduce chance of hangs, use a unique
Windows class name for the main window, and search for that rather
than caption.
Post by DClyde
Post by anealc
Hi there,
I am creating an application which is only allowed to run on Windows once.
If the
user attempts to invoke a second instance this second instance shows a
message to the effect that the program is already running, before switching
to the original instance.
My question is that is there a Microsoft standard for this behaviour? The
only Microsoft app that I can think of that does this is Media Centre, but
that doesn't show any message.
Thanks
Aneal
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, MVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com

Loading...