Results 1 to 5 of 5

Thread: How to find whether an instance of an application is already running?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Auckland, NZ
    Posts
    182

    How to find whether an instance of an application is already running?

    How can I find whether an instance of an application is
    already running in order to prevent from opening several
    instances at once?

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is one way.
    VB Code:
    1. If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then MsgBox("Multiple Instances are running!")

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Auckland, NZ
    Posts
    182
    Thanks, Edneeis.

    It is working well.

  4. #4
    Addicted Member
    Join Date
    Aug 2001
    Posts
    164
    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:
    1. If Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
    2. 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.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width