SoFunction
Updated on 2025-03-07

Setting the C# form program can only be started once

Add the following code to the main function of the program
bool createdNew;
instance = new (true, "MutexName", out createdNew);
if (createdNew)
{
(new LoginForm());
();
}
else
{
();
}
It can also be written in the following form, a form can only be started once
Form1 a = new Form1();
bool createdNew;
instance = new (true, "MutexName", out createdNew);
if (createdNew)
{
();
();
}
else
{
();
}