Special

Clearance Sale!

We've been publishing for over five years now and it's time to clear out our inventory of back issues, so we're slashing prices!

RBD Magazines

Check out this amazing clearance sale of all our past issues. Missing some issues? This is a great time to complete your RBD collection. Save up to 40% off the regular price of our printed back issue packages. These prices are only good until the end of the year May 2008 and supplies are limited, so place your order today.

Article Preview


Buy Now

Print:
PDF:

Intel corner

Allow only one application instance to run at the same time.

About using the Windows API to create a mutex object.

Issue: 2.2 (October/November 2003)
Author: Christian Schmitz
Author Bio: Christian Schmitz is the creator of the Monkeybread Software REALbasic Plugins.
Article Description: No description available.
Article Length (in bytes): 9,923
Starting Page Number: 42
RBD Number: 2220
Resource File(s):

Download Icon 2220exe.sit Updated: Monday, October 27, 2003 at 1:31 PM
Download Icon 2220rb.sit Updated: Monday, October 27, 2003 at 1:31 PM

Related Web Link(s):

http://msdn.microsoft.com/library/en-us/dllproc/base/releasemutex.asp

Known Limitations: None

Excerpt of article text...

What do we want?

If you double click an application file in Windows, you will notice that the application is launched even if it is already running. So you can launch several application instances from one application file in Windows.

For many applications this is not what developers want. So they do some magic stuff to avoid the second application instance. You can do this several ways:

1. You can check the temporary folder to see if there is a special file there. If the file exists you have a second copy running, else you create the file. As your application will fail to delete the file when it crashes, we don't use this way to solve our problem.

2. If you do networking in your application via sockets, you can handle the case of a special string being received from an incoming socket by responding with some other string. When your application is started, have it open a connection to "127.0.0.1" (localhost). If the connection is accepted and the other side answers with the correct string, you know your application is already running.

...End of Excerpt. Please purchase the magazine to read the full article.

Article copyrighted by REALbasic Developer magazine. All rights reserved.


 


|

 


Weblog Commenting and Trackback by HaloScan.com