How can I find whether an instance of an application is
already running in order to prevent from opening several
instances at once?
How can I find whether an instance of an application is
already running in order to prevent from opening several
instances at once?
Here is one way.
VB Code:
If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then MsgBox("Multiple Instances are running!")
Thanks, Edneeis.
It is working well.
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..
VB Code:
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.
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.