[STAThread]
public static void Main(string[] args)
{
//声明互斥体。
Mutex mutex = new Mutex(false, "ThisShouldOnlyRunOnce");
//判断互斥体是否使用中。
bool Running = !mutex.WaitOne(0, false);
if (! Running)
Application.Run(new FormLogin());
else
MessageBox.Show("应用程序已经启动!");
}
public static void Main(string[] args)
{
//声明互斥体。
Mutex mutex = new Mutex(false, "ThisShouldOnlyRunOnce");
//判断互斥体是否使用中。
bool Running = !mutex.WaitOne(0, false);
if (! Running)
Application.Run(new FormLogin());
else
MessageBox.Show("应用程序已经启动!");
}
本文介绍如何利用Mutex确保Windows应用程序仅能同时运行一个实例。通过创建Mutex并检查其状态,可以有效防止应用程序被重复启动,提升用户体验。

755

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



