C#如何關閉指定進程
阿新 • • 發佈:2018-12-13
() env sse reac esb time ssa exce mina
public static void KillProcess(string strProcessesByName)//關閉線程 { foreach (Process p in Process.GetProcesses())//GetProcessesByName(strProcessesByName)) { if (p.ProcessName.ToUpper().Contains("你要關閉的進程名字")) { try { p.Kill(); p.WaitForExit();// possibly with a timeout } catch (Win32Exception e) { MessageBox.Show(e.Message.ToString()); // process was terminating or can‘t be terminated - deal with it } catch (InvalidOperationException e) { MessageBox.Show(e.Message.ToString());// process has already exited - might be able to let this one go } } } }
或者這樣關閉自己
Environment.Exit(0);
C#如何關閉指定進程