使用线程互斥变量. 通过定义互斥变量来判断是否已运行实例
[STAThread]
static void Main() {
//是否已经运行了实例
bool runone;
System.Threading.Mutex run = new System.Threading.Mutex(true, "FormsEditor", out runone);
if(runone)
{
run.ReleaseMutex();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
MessageBox.Show("已经运行了一个实例了。");
}
}