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

Mutex, Take 2

Allow only one application instance to run at a time

Issue: 5.2 (January/February 2007)
Author: Christian Schmitz, cSchmitz-at-rbdeveloper.com
Article Description: No description available.
Article Length (in bytes): 5,595
Starting Page Number: 42
RBD Number: 5217
Resource File(s):

Download Icon 5217.zip Updated: Monday, January 15, 2007 at 1:16 PM

Related Link(s): None
Known Limitations: None

Excerpt of article text...

Years ago we had an article in the RB Developer about how to make a mutex in Realbasic using declares. With newer REALbasic versions a Mutex class was introduced. So here is an updated article for you.

What do we want?

If you doubleclick 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 on Windows.

For several applications this is not wanted by the developer, so they do some magic stuff to avoid the second application instance. You can do this in several ways:

1. You can check a temporary folder to see if there is a special file located there. If the file exists, then you have a second copy running, else you create the file. Because your application will fail to delete the file if it crashes, this is not a good approach to solve our problem.

2. If you do networking in your application via sockets, you can send a special string to the socket to see if another instance of your application answers with a special return string. When your application is started it opens a connection to "127.0.0.1" (localhost). If the connection is accepted and the other side answers with the correct string, you know that another instance of 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