Test for multiple application executions (VB.NET)?

  • Thread starter Thread starter Larry Woods
  • Start date Start date
L

Larry Woods

Can't find the right object...

How do I test to see if my application is already executing; i.e., multiple
application executions?

TIA,

Larry Woods
 
There is probably an easier way, but I get a list of the processes by
my apps name, then see if there is more than 1. If so, there is
already one running, otherwise there isn't.

Dim pList() As Process
Dim myProcess As System.Diagnostics.Process
pList = myProcess.GetProcessesByName("<appname>")
Dim i As Integer = 0
For Each myProcess In pList
' MsgBox(myProcess.ProcessName)
i += 1
Next
If (i > 1) Then
MsgBox("already running!", MsgBoxStyle.Exclamation,
"Error")
Application.Exit()
End If


Hope this helps.
 
Larry,

And the alternative, on from Not Aaron.

\\\
Private mut As New Threading.Mutex(True, "myProgram", mutCreated)
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not mutCreated Then Me.Close()
'etc
End Sub
///

Both the solution that Not Aaron gives and that I show have problems when
there is another program with the same name running. When you want to avoid
that, than look in the link that Herfried surely will give on this question
to the solution from Tom Shelton.

I hope this helps a little bit?

Cor
 

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