设置C#窗体程序只能启动一次
程序员文章站
2023-11-22 11:05:34
在程序的main函数中加入以下代码 bool creatednew; system.threading.mutex instance = new system.thread...
在程序的main函数中加入以下代码
bool creatednew;
system.threading.mutex instance = new system.threading.mutex(true, "mutexname", out creatednew);
if (creatednew)
{
application.run(new loginform());
instance.releasemutex();
}
else
{
application.exit();
}
还可以写成以下形式,一个窗体只能启动一次
form1 a = new form1();
bool creatednew;
system.threading.mutex instance = new system.threading.mutex(true, "mutexname", out creatednew);
if (creatednew)
{
a.showdialog();
instance.releasemutex();
}
else
{
a.close();
}
bool creatednew;
system.threading.mutex instance = new system.threading.mutex(true, "mutexname", out creatednew);
if (creatednew)
{
application.run(new loginform());
instance.releasemutex();
}
else
{
application.exit();
}
还可以写成以下形式,一个窗体只能启动一次
form1 a = new form1();
bool creatednew;
system.threading.mutex instance = new system.threading.mutex(true, "mutexname", out creatednew);
if (creatednew)
{
a.showdialog();
instance.releasemutex();
}
else
{
a.close();
}