winForm:
1.利用同步基元(Mutex),实现共享资源的互斥访问
Public Shared Sub Main()
Dim oMT As System.Threading.Mutex
oMT = New System.threading.Mutex(False, Application.ProductName)
If oMT.WaitOne(100, False) Then
Application.Run(New Form1)
oMT.ReleaseMutex()
Else
MessageBox.Show("Application has started!")
Application.Exit()
End If
oMT.Close()
End Sub
2.搜索同名进程
Dim localByName As Process() = Process.GetProcessesByName _
(Process.GetCurrentProcess.ProcessName)
If localByName.Length > 1 Then
MessageBox.Show("Application has started!")
Application.Exit()
End If