Mutex mutexZSSPY = new Mutex(false, "ZSSPY", out bool status);
if (status)
{
Application.Run(new Form());
}
else
{
MessageBox.Show("ZSSPY is running!", "ZS SPY error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
I Use this code block to create a mutex to avoid opening the program multiple times,but this
// mutex can’t create success.
using (Mutex mutexZSSPY = new System.Threading.Mutex(false, "ZSSPY", out status))
{
if (status == true)
{
Application.Run(new Form1());
}
else
{
MessageBox.Show("ZSSPY is running!", "ZS SPY error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I use this code block ,then can create mutex successfully.I want to know why.