protectedoverridevoidOnStartup(StartupEventArgs e){base.OnStartup(e);var process =Process.GetProcessesByName("Dog");if(process.Count()>1){var list = process.ToList();
list.Sort((p1,p2)=>p1.StartTime.CompareTo(p2.StartTime));
list[0].Kill();}}
1
2
3
4
5
6
7
8
9
1.2 程序打开后不再打开新程序
protectedoverridevoidOnStartup(StartupEventArgs e){base.OnStartup(e);var process =Process.GetProcessesByName("Dog");if(process.Count()>1){
MessageBox.Show("已经打开一个程序");
Process.GetCurrentProcess().Kill();}}