using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; using System.Windows.Forms; namespace Update { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var program = "PEIS.exe"; // 检查程序是否正在运行 Process[] processes = Process.GetProcessesByName(program); if (processes.Length > 0) { // 关闭程序 foreach (var process in processes) { process.Kill(); process.WaitForExit(); // 等待程序退出 Console.WriteLine($@"Closed existing instance of {program}"); } // 等待2秒 Thread.Sleep(1000); } Application.Run(new Form1()); } } }