本文介绍了互斥锁没有按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定我的应用程序只能在一台机器上运行一次,并且我使用Mutex实现了一个解决方案
。该解决方案已多次发布,但

我找到的一个很棒的链接是



问题是,当我切换用户(XP Professional)时,第二个用户可以打开应用程序的第二个实例
!如何防止这种情况?


这是我的代码的相关部分:


Sub Main()

Dim vBool As Boolean

Dim FirstInstance As New Mutex(False,UniqueMutexName",vBool)

如果不是vBool那么

将消息发布给用户并退出。

结束如果

解决方案




MsgBox(无法启动此文件的多个副本,
MsgBoxStyle.Exclamation )
Me.Close()




如果有多个应用程序具有相同的

进程名称,则此代码将失败。流程名称不一定是unque。


-

MS Herfried K. Wagner

MVP< URL:http:/ /dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>



MsgBox(不能启动thisgram的多个副本,
MsgBoxStyle.Exclamation)
Me.Close()



如果有多个具有相同
进程名称的应用程序,则此代码将失败。流程名称不一定是unque。

- MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://dotnet.mvps.org/dotnet/faqs/>



I need to be certain my application only runs once on a machine, and I
implemented a solution using Mutex. The solution was posted many times, but
one great link I found is
http://www.yoda.arachsys.com/csharp/...ation.instance

The problem is, when I switch users (XP Professional) the second user can
open a second instance of the application! How can I prevent this?

Here''s the relevant part of my code:

Sub Main()
Dim vBool As Boolean
Dim FirstInstance As New Mutex(False, "UniqueMutexName", vBool)
If Not vBool Then
Post message to user and exit.
End If

解决方案




MsgBox("Cannot start more than one copy of thisgram",
MsgBoxStyle.Exclamation)
Me.Close()



This code will fail if there is more than one application with the same
process name. Process names are not necessarily unque.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



MsgBox("Cannot start more than one copy of thisgram",
MsgBoxStyle.Exclamation)
Me.Close()



This code will fail if there is more than one application with the same
process name. Process names are not necessarily unque.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



这篇关于互斥锁没有按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 20:28
查看更多