VB.NET阻止程序重复启动

以下两种方法来自qq群,未经测试:


方法一:

If (UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0) Then
MessageBox.Show("当前程序已启动,请使用Alt+Tab键进行切换!", "禁止运行 ", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End
Exit Sub
End If


方法二:

        Dim bExist As Boolean = False
        Dim MyMutex As New System.Threading.Mutex(True, "随便给个名字", bExist) '互斥进程
  
        If bExist = False Then
            MessageBox.Show("程序已经运行!", "禁止多开", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Dispose()
            End
        End If 

posted @ 2012-06-19 15:10  rf8862  阅读(794)  评论(0编辑  收藏  举报