Check if app is already running

  • Thread starter Thread starter Michael Passalacqua
  • Start date Start date
M

Michael Passalacqua

In VB.NET, how do you check to see if an instance of your application is
already running?

Michael Passalacqua
Portland Community College
CIS Faculty
 
Michael Passalacqua said:
In VB.NET, how do you check to see if an instance of your application
is already running?

It's been asked and answered two hours ago. Subject: Is app already running?
 
If you make a public function similar to this

Public Shared Function PrevInstance() As Process

Dim c As Process = Process.GetCurrentProcess()

Dim p As Process

For Each p In Process.GetProcessesByName(c.ProcessName)

If p.Id <> c.Id Then

If p.MainModule.FileName = c.MainModule.FileName Then

Return p

End If

End If

Next p

Return Nothing

End Function

And then call it from say the Form load event or a sub main

If Not PrevInstance() Is Nothing Then

MsgBox("Myapp is already running !", MsgBoxStyle.Information, "Myapp")

End

' Else

' Exit.

End If

Hope this helps...

meh
 
Back
Top