Application Instances

  • Thread starter Thread starter JMMB
  • Start date Start date
Hello,

JMMB said:
Is there a way to avoid the user open more than one
instance of my application?

\\\
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
///

- or -

\\\
Imports System.Threading
..
..
..
Dim m As Mutex = _
New Mutex(False, "{11C92606-65D9-4df2-9AEA-B6A4DA91BCE2}")
If m.WaitOne(10, False) Then
Application.Run(New Form1())
m.ReleaseMutex()
Else
MessageBox.Show("Application already running!")
End If
///
 
Back
Top