可以使用互斥体Mutex类型完成此功能。见如下代码:
[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("应用程序已经启动!");
}
[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("应用程序已经启动!");
}
博客介绍了使用互斥体Mutex类型实现特定功能的方法。通过声明互斥体,判断其是否正在使用,若未使用则运行登录窗体,若已使用则提示应用程序已启动,并给出了相应的代码示例。

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



