Detecting that a program is already running

  • Thread starter Thread starter Joecx
  • Start date Start date
J

Joecx

Hi
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already
running? I know I could do this with a dummy file by putting something in the
file while it's running and emptying the file when it's not running, but I was
hoping for something a little more professional. Has anyone done this yet?

Joe
 
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length >
0 Then
' exit application or display message
End If
-- Code ends --

Hope this helps.
 
* "Matt S said:
You could try something like...

-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length >
0 Then
' exit application or display message
End If

Notice that the application name isn't necessarily unique.
 
-- Code starts --
If
Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length
' exit application or display message
End If
-- Code ends --

Note that this code will detect it self. It should stand .Length > 1.
BTW ProcessName is not necessary unique.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top