C# 如何限制用户打开多个exe实例
我的应用程序在两个构建版本中以exe的形式发布——DeveloperBuild和ClientBuildUAT。 DeveloperBuild用于内部开发人员和QA测试,而ClientBuild用于最终客户DeveloperBuild和ClientBuild实际上是程序集名称 我想限制用户打开多个构建实例。简单地说,用户应该能够打开单个DeveloperBuild实例 同时创建ClientBuild的单个实例, 但不应允许用户同时打开DeveloperBuild或ClientBuild的多个实例 这就是我尝试过的。下面的代码帮助我维护应用程序的单个实例, 但它并没有区分开发人员构建和客户机构建。我希望用户能够同时打开两个构建的单个实例 ///应用程序的入口点C# 如何限制用户打开多个exe实例,c#,.net,build,mutex,semaphore,C#,.net,Build,Mutex,Semaphore,我的应用程序在两个构建版本中以exe的形式发布——DeveloperBuild和ClientBuildUAT。 DeveloperBuild用于内部开发人员和QA测试,而ClientBuild用于最终客户DeveloperBuild和ClientBuild实际上是程序集名称 我想限制用户打开多个构建实例。简单地说,用户应该能够打开单个DeveloperBuild实例 同时创建ClientBuild的单个实例, 但不应允许用户同时打开DeveloperBuild或ClientBuild的多个实例
protected override void OnStartup(StartupEventArgs e)
{
const string sMutexUniqueName = "MutexForMyApp";
bool createdNew;
_mutex = new Mutex(true, sMutexUniqueName, out createdNew);
// App is already running! Exiting the application
if (!createdNew)
{
MessageBox.Show("App is already running, so cannot run another instance !","MyApp",MessageBoxButton.OK,MessageBoxImage.Exclamation);
Application.Current.Shutdown();
}
base.OnStartup(e);
//Initialize the bootstrapper and run
var bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
每个生成的互斥体名称必须是唯一的。因为每个版本有不同的程序集名称,所以可以将此名称包括在互斥体的名称中,如下所述
protected override void OnStartup(StartupEventArgs e)
{
string sMutexUniqueName = "MutexForMyApp" + Assembly.GetExecutingAssembly().GetName().Name;
bool createdNew;
_mutex = new Mutex(true, sMutexUniqueName, out createdNew);
// App is already running! Exiting the application
if (!createdNew)
{
MessageBox.Show("App is already running, so cannot run another instance !","MyApp",MessageBoxButton.OK,MessageBoxImage.Exclamation);
Application.Current.Shutdown();
}
base.OnStartup(e);
//Initialize the bootstrapper and run
var bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
哪个programsenvironment客户端用于构建和运行?用户使用什么操作系统?@Fedor环境是Dev和UAT。使用的操作系统是Windows。您是否尝试使用Windows注册表而不是互斥,通过它设置并获取值?