Kurt Posted June 10, 2003 Posted June 10, 2003 How to find out whether there's already running an instance of your application when a user wants to start it? I would like to allow only one instance running on a machine. Quote qrt
*Gurus* divil Posted June 10, 2003 *Gurus* Posted June 10, 2003 Straight from the help: In Visual Basic 6.0, the PrevInstance property of the App object was used to determine if a previous instance of an application was running. There is no equivalent for this property in Visual Basic .NET; however, the following code can be used to test for a previous instance: ' Visual Basic .NET Function PrevInstance() As Boolean If Ubound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then Return True Else Return False End If End Function Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Kurt Posted June 12, 2003 Author Posted June 12, 2003 thanx divil. Any suggestions where the best placement would be to call this check (in the constructor of the start up form or something?), so I can cancel the start up of a second instance? Quote qrt
*Gurus* divil Posted June 12, 2003 *Gurus* Posted June 12, 2003 Make yourself a Sub Main to start the application, then only do your Application.Run(new form1()) if the check succeeds. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Winston Posted June 14, 2003 Posted June 14, 2003 thats wat i used although it works fine but theres a work around which is renaming the exe Quote
Leaders quwiltw Posted June 17, 2003 Leaders Posted June 17, 2003 Check out [msdn]System.Threading.Mutex[/msdn]. Which will allow you to do something like this, which prevents any renaming workarounds. Dim objLock As New System.Threading.Mutex(False, "MyAppLock") Dim blnIsRunning As Boolean = Not mtxLock.WaitOne(0, False) Quote --tim
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.