DVL Software Limited
[ About | Services | Products | Search | Feedback | Support ]

PowerBuilder Tips

Single Instance

Back to the Tips


I've never like the approach of using FindWindow.  I thought it was too easy to go wrong and imposed a restriction on you with regards to naming conventions.  This solution involves both DDE and a semaphore.  When combined, they give the best of both worlds.

When I started looking for a solution to this problem, I found the DDE method at http://www.mosystems.com/pbindex.htm and the mutex method at http://www.teleport.com/~wagnerc/powerbuilder_faq.html.   Each solution had it own advantages. Both were independent of the window name and both used well known and well used strategies  I liked the mutex (which is short mutual exclusion) because it was designed to provide exclusive use of a resource.   However, the DDE method had one advantage over all of the other methods: it allowed application to application communication.  By combining the two methods, I found a solution which I think is both robust and eloquent.

The objective is to have at most a single instance of the application.  If the user attempts to start a second instance, we will merely bring the first instance to the front.  Both steps have been incorporated into an single object.  We determine if there is a previous instance of the application by using the CreateMutex function.   If the function succeeds, we are the first instance.  If it fails, there is a previous instance and we should activate it.  The activation process uses DDE.   We open a channel to the existing instance and tell it to activate itself.   Unfortunately, we need to open a window to do this as DDE only operates between windows.  We have created a w_dde window for this purpose.

An example of this technique is available from our FTP server.  If you have any questions, please do not hesitate to ask.  As always, comment and criticism on this technique are appreciated.


Back to the Tips

[ About | Services | Products | Search | Feedback | Support ]

This page last updated: Tuesday, 29 February 2000
Copyright 1997, 1998, 1999, 2000 DVL Software Limited.  All rights reserved.