S
Samuel R. Neff
Most of the time what I've read is that to keep only one instance of
an app running one should use a Mutex. However, we have an existing
app that uses GetProcessByName() to ensure only one instance is
running.
What are the advantages of a Mutex besides protecting against name
collision (which I imagine can be high since GetProcessesByName uses
the short name of the executable without the path)?
Thanks,
Sam
Shared Sub Main(ByVal CmdArgs() As String)
Dim ThisProcess As Process = Process.GetCurrentProcess()
Dim AllProcesses As Process() =
Process.GetProcessesByName(ThisProcess.ProcessName)
If (AllProcesses.Length > 1) Then
MessageBox.Show(ThisProcess.ProcessName + " is already
running.", ThisProcess.ProcessName, MessageBoxButtons.OK,
MessageBoxIcon.Error)
Else
Application.Run(New frmMain)
End If
End Sub
an app running one should use a Mutex. However, we have an existing
app that uses GetProcessByName() to ensure only one instance is
running.
What are the advantages of a Mutex besides protecting against name
collision (which I imagine can be high since GetProcessesByName uses
the short name of the executable without the path)?
Thanks,
Sam
Shared Sub Main(ByVal CmdArgs() As String)
Dim ThisProcess As Process = Process.GetCurrentProcess()
Dim AllProcesses As Process() =
Process.GetProcessesByName(ThisProcess.ProcessName)
If (AllProcesses.Length > 1) Then
MessageBox.Show(ThisProcess.ProcessName + " is already
running.", ThisProcess.ProcessName, MessageBoxButtons.OK,
MessageBoxIcon.Error)
Else
Application.Run(New frmMain)
End If
End Sub