Imports System
'Imports System.Threading
Module Module1
Sub Main()
Dim mutex As System.Threading.Mutex = New Threading.Mutex(False, "this should only run once")
Dim run As Boolean = True
run = mutex.WaitOne(0, False)
If run = False Then
MsgBox("System is Running,Can't Run It Again")
Exit Sub
End If
Console.WriteLine("これは一つの簡単な例です。")
'Console.ReadLine()
MsgBox("System is Running")
'Thread.Sleep(5000)
End Sub
End Module
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
他の方法:
Dim _isProcessRunning As Int32
_isProcessRunning = System.Diagnostics.Process.GetProcessesByName( _
System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length
If _isProcessRunning <> 1 Then
MsgBox("System is Runing,Can't Run It Again")
Exit Sub
End If