class Program
{
//static ManualResetEventSlim MainSignaledresetEvent;
//static ManualResetEventSlim DoWorkSignaledResetEvent;
public static void Main()
{
bool firstApplictionInstance;
string mutexName = Assembly.GetEntryAssembly().FullName;
using (Mutex mutex = new Mutex(false, mutexName, out firstApplictionInstance))
{
if (!firstApplictionInstance)
{
Console.WriteLine("This appliction is already running");
Console.ReadLine();
}
else
{
Console.WriteLine("Enter to ShutDown");
Console.ReadLine();
}
}
}
}
```
C# 使用Mutex禁止多次开启同一个程序
最新推荐文章于 2025-09-07 09:18:40 发布
本文通过一个C#代码示例,展示了如何使用Mutex确保同一应用程序的唯一实例运行。当尝试启动第二个实例时,程序会检查Mutex状态并提示已有一个实例正在运行。
215

被折叠的 条评论
为什么被折叠?



