全球互斥 [英] Global Mutex

查看:58
本文介绍了全球互斥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的大家好,

这是我的情况:

在多用户环境中,应防止2个应用程序同时运行,例如:

In a multi-user environment 2 applications should be prevented from running simultaneously, meaning for example:

从终端A执行应用程序A.在执行应用程序A时,应防止从任何其他网络终端执行应用程序B.

Application A is executed from terminal A. While application A is executed application B should be prevented from executed from any other network terminal.

使用全局互斥锁应防止来自其他终端的任何其他用户 在执行应用程序A的同时执行应用程序B?

Using a Global Mutex should prevent any other user from another terminal to execute application B, while application A is executed?

预先感谢

推荐答案

互斥锁如何做到这一点?

How could a mutex do that?

如果在应用程序A和应用程序B中使用了互斥锁,则必须启动该应用程序.如果某个终端已经在运行应用程序A或应用程序B,则互斥锁必须为每个终端都弄清楚?

If you used a mutex in application A and application B then the application would have to launch. The mutex would have to figure out for every terminal if a terminal is already running application A or application B wouldn't it?

在我看来,如果您使用的是终端服务,则当有人从服务器运行应用程序A时,可以在服务器上设置注册表项或其他内容.然后,当从终端启动应用程序B时,如果注册表将其在表单加载期间关闭 服务器上的条目表示不启动,因为应用程序A已经在某处运行.当应用程序A关闭时,它会更改注册表项.

It seems to me if you're using Terminal Services that when someone runs application A from a server a registry entry or something could be set on the server. Then when application B is launched from a terminal it closes down during form load if the registry entry on the server means not to launch because application A is already running somewhere. And when application A shuts down it changes the registry entry.

因此,如果注册表项是字符串中的值,那么如果没有任何应用程序在运行,则不会有任何结果.如果什么都不是,并且应用程序A启动,则可以将其设置为"AppA1".如果启动了另一个应用程序A,它将在注册表中看到一个值 入口.如果存在"AppA1"的值,则它将其更改为"AppA2".在此期间,如果应用程序B启动,它将看到一个"AppA".已从注册表项运行,因此它将关闭并且无法运行.当申请 关闭它会从注册表项的值中减去一个.如果该值="AppA1",则返回"AppA1".最后一个应用程序的关闭将使该值更改为空.

So if the registry entry was a value in string it would be nothing if no apps were running. If it was nothing and an application A launched it could be set to "AppA1". If another application A was started it would see there is a value in the registry entry. If a value of "AppA1" was there it would change it to "AppA2". During this time if an application B launched it would see that an "AppA" is already running from the registry entry so it would shut down and not run. When an application A shutdown it would subtract one from the value of the registry entry. If the value = "AppA1" the last application A closing would change the value to nothing.

您不知道该在服务器注册表的哪个区域执行此操作.也许这甚至不是一个合适的方法.但是我很难相信Mutex可以用来做这样的事情.

Which area of a servers registry would you do this in I've no idea. Maybe it's not even an appropriate method. But I've difficulty believing a Mutex could be used to do something like this.

尽管有可能您需要在终端调用应用程序A或B时在服务器上启动应用程序.然后哪个应用程序知道A或B是否正在某个地方运行,并且如果A已经在某个地方运行,则不允许B运行. 反之亦然.而且,如果A或B已经在运行,则该应用程序将杀死由其他某个终端所启动的其他任何实例,这些其他实例要求A或B运行.

Although it's possible you could launch an app on the server when either an application A or B is called for by a terminal. Which the app then knows if an A or B is running somewhere and will not allow a B to run if an A is already running somewhere or vice versa. And if an A or B is already running the app will kill any other instance of itself launched by some other terminal calling for an A or B to run.


这篇关于全球互斥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆