On Mon, 26 Mar 2007 08:47:53 -0700, Raaj <ra***********@yahoo.comwrote:
A probable work around if you intend to avoid mutex, Give your main
form a unique name that has *good* chances of being unique and then
use the FindWindow API to retrieve its window handle.
You can check for the existence of the instance in the entry point of
your application and prevent from creating an instance if it is
already instantiated.
One problem with this method is that there is no way to guarantee one
instance of the application will have already created its window when the
next instance goes to check for it and vice a versa.
With the mutex, exactly one of the instances will actually create the
mutex, and the operating system guarantees exclusive access to the mutex.
There's no similar conflict resolution when checking for the application
window. The application can detect the case where the race condition
results in more than one instance running anyway, but then it still needs
to deal with deciding which instance "wins" and which instances have to
exit.
Basically, the mutex method is simple and provides guarantees that other
methods don't.
Pete