防止服务器实例中有多个实例使用相同的用户名 [英] Prevent multiple instances in server same username

查看:55
本文介绍了防止服务器实例中有多个实例使用相同的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个托管在一台服务器中的应用程序.许多用户通过远程桌面连接访问它,但是有时我在任务管理器中看到同一用户打开了2-x实例.我需要防止同一用户无法打开多个实例.但是请注意,该程序可以由不同的用户多次打开.请原谅我我的英语.谢谢.

I developed an application that is hosted in one server. Many users access to it via Remote Desktop connection, but sometimes I saw in the task manager that the same user has opened 2-x instances. I need prevent that the same user can't open multiple instances. But notice that the program can be opened multiple times by different users. Please forgive me my English. Thanks.

PS:我正在使用Winforms和C#

PS: I'm using Winforms and C#

推荐答案

您可以使用用户名创建互斥体.

You can create a mutex with the user's name.

bool b = true;
Mutex mutex = new Mutex(true, Environment.UserName.ToLowerInvariant() , out b);
if (!b) throw new InvalidOperationException("Another instance is running");

这篇关于防止服务器实例中有多个实例使用相同的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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