【发布时间】:2018-11-07 00:16:03
【问题描述】:
我的应用程序在两个构建版本中作为 exe 发布 - DeveloperBuild 和 ClientBuild(UAT)。 DeveloperBuild 适用于内部开发人员和 QA 测试,而 ClientBuild 适用于最终客户。 'DeveloperBuild' 和 'ClientBuild' 实际上是程序集名称。
我想限制用户打开多个构建实例。简单来说,用户应该能够打开一个 DeveloperBuild 实例 和 ClientBuild 同时的单个实例, 但不应允许用户同时打开多个 DeveloperBuild 或 ClientBuild 实例。
这是我尝试过的。下面的代码帮助我维护我的应用程序的单个实例, 但它不区分 Developer Build 和 Client Build。我希望用户能够同时打开两个构建的单个实例。
/// 应用程序的入口点
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();
}
【问题讨论】:
-
哪些程序(环境)客户端用于构建和运行?用户使用什么操作系统?
-
@Fedor 环境是 Dev 和 UAT。使用的操作系统是 Windows。
-
您是否尝试使用 Windows 注册表而不是
Mutex,通过它设置和获取值?
标签: c# .net build mutex semaphore