Click to See Complete Forum and Search --> : How to find whether an instance of an application is already running?
bona
Jan 12th, 2003, 01:35 AM
How can I find whether an instance of an application is
already running in order to prevent from opening several
instances at once?
Edneeis
Jan 12th, 2003, 03:05 AM
Here is one way.
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then MsgBox("Multiple Instances are running!")
bona
Jan 12th, 2003, 03:11 AM
Thanks, Edneeis.
It is working well.
mohsinof
Jan 12th, 2003, 01:29 PM
Hi..
Can you clarify this alittle bit more, and how to use it should it be used in the first form like in splash form and should it be used in Form_load event..
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
MsgBox("Multiple Instances are running!")
What is process do I have to define in it as a variable?
Please if you could explain it with more details..
Thanks in advance for your help.
Edneeis
Jan 12th, 2003, 07:56 PM
It doesn't matter where you use it. A process is like a thread, if you check the windows Task Manager you'll see all the processes running on the machine (if you have windows 2k or higher). So what it does is get a reference to the current process (the application's process) and then check how many it has with that name. If there are more than 1 with that name then more than 1 instance is running. So you don't have to declare any variable or anything just cut and paste the code and it should work fine.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.