Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 5.2

COLUMN

Mutex, Take 2

Allow only one application instance to run at a time

Issue: 5.2 (January/February 2007)
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): 6,778
Starting Page Number: 42
Article Number: 5217
Resource File(s):

Download Icon 5217.zip Updated: 2013-03-11 19:07:59

Related Link(s): 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.