一段检测当前进程是否已经在运行了的代码,非常实用!

来源:互联网 发布:淘宝适合卖什么 编辑:程序博客网 时间:2024/05/17 05:13

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

 
原创粉丝点击