Private Function IsAlreadyRunningInstance() As Boolean
Dim current As process = System.Diagnostics.Process.GetCurrentProcess()
Dim processes As process() = System.Diagnostics.Process.GetProcessesByName(current.ProcessName)
'Loop through the running processes in with the same name
Dim process As process
For Each process In processes
'Ignore the current process
If process.Id <> current.Id Then
'Make sure that the process is running from the exe file.
If [Assembly].GetExecutingAssembly().Location.Replace("/", "/") = current.MainModule.FileName Then
'Return true.
Return True
End If
End If
Next process
'No other instance was found, return false.
Return False
End Function
本文提供了一段Visual Basic .NET代码,用于检查当前应用程序是否已有运行实例。通过获取与当前进程名称相同的进程并进行比较,可以判断是否存在重复运行的情况。
3909

被折叠的 条评论
为什么被折叠?



