当不应用程序框架时,可以通过定义互斥变量来判断是否已运行实例:
1 Sub Main() 2 Dim isNotRunning As Boolean = True 3 Static run As New System.Threading.Mutex(True, "SampleForm", isNotRunning) 4 If isNotRunning Then 5 run.ReleaseMutex() 6 Application.Run(New SampleForm) 7 End If 8 End Sub
将SampleForm替换为要运行的窗体即可。