
Preventing Multiple Launches of the same App
Ok I too wanted to stop multiple instances of the same app and to swap to
the current app without restarting a new instance. I have tried numerous
different methods but this seems too work best for my apps.
Using the Main sub as your start up sub then checking to see if the
application is already running;
if it is - then activate and place on top of the desktop, then end the
second app should never actually be seen by user.
if not - then show the main form which in turn will execute its
initialize, activate, and load routines as usual.
Heres the code I use. N.B: appactive needs a string or string variable of
the Form caption of the instance you want to swap to.
Private Sub Main()
If App.PrevInstance = True Then
AppActivate "Your Main form Caption here"
End
Else
MainFrm.Show
End If
End Sub
Clear as mud?
Christopher Hyett
Imaginative Solutions
Quote:
>I've written a program which reads the results from an HP meter.
>However, my users tend to launch several copies of it, and when two
>copies are trying to read the meter, the whole system locks. I'd like
>to know of a simple way to tell if a copy is already running, and task
>switch to that copy if the program executed. Thanks for any help.
>Jeff