protected override void OnStartup(StartupEventArgs e) 2{ 3 Process process = Process.GetCurrentProcess(); 4 5 foreach (Process p in Process.GetProcessesByName(process.ProcessName)) 6 { 7 if (p.Id != process.Id) 8 { 9 10 //关闭第二个启动的程序 11 12 MessageBox.Show("您的程序已经启动!"); 13 14 Application.Current.Shutdown(); 15 16 return; 17 18 } 19 } 20 base.OnStartup(e); 21}