var preInstance = Process.GetProcesses().FirstOrDefault(p => { try { if (p.Id != Process.GetCurrentProcess().Id && p.MainModule != null && p.MainModule.FileName.ToLower() == Assembly.GetExecutingAssembly().Location.ToLower()) return true; return false; } catch { return false; } }); if (preInstance != null) { MessageBox.Show("程序已在运行!"); return; }