让程序只运行一个实例的方法

using System.Threading;

public class Class1
{
    [STAThread]
    
static void Main()
    
{
        Mutex mutex 
= new Mutex(false"MutexName");
        
if (!mutex.WaitOne(0false))
        
{
            mutex.Close();
            MessageBox.Show(
"Another instance is aready running!");
            
return;
        }


        Application.Run(
new Form1());
    }

}

原文地址:https://www.cnblogs.com/aipeli/p/165149.html