using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ZB.QueueSys.Common { public class ProcessHelpers { //private static ProcessHelper instance; //public static ProcessHelper Instance //{ // get // { // if (instance == null) instance = new ProcessHelper(); // return ProcessHelper.instance; // } //} //定义一个用于保存静态变量的实例 private static ProcessHelpers instance = null; //定义一个保证线程同步的标识 private static readonly object locker = new object(); //构造函数为私有,使外界不能创建该类的实例 private ProcessHelpers() { } public static ProcessHelpers Instance { get { if (instance == null) { lock (locker) { if (instance == null) instance = new ProcessHelpers(); } } return instance; } } /// <summary> /// 关闭进程 /// </summary> /// <param name="processName">进程名</param> public void KillProcessByName(string processName) { try { Process[] myproc = Process.GetProcesses(); foreach (Process item in myproc) { if (item.ProcessName == processName) { item.CloseMainWindow(); item.Kill(); } } } catch { return; } } /// <summary> /// 启动进程 /// </summary> /// <param name="processName">进程名,完全限定名</param> public void StartProcessByName(string processName) { System.Diagnostics.Process.Start(processName); //Process process = new Process();//声明一个进程类对象 //process.StartInfo.FileName = processName;//Application.StartupPath + "\\AutoUpdate.exe"; //process.Start(); } public void StartProcessByName(string processName, string param) { //System.Diagnostics.Process.Start(processName); Process p = new Process();//声明一个进程类对象 p.StartInfo.FileName = processName;// Application.StartupPath + "\\AutoUpdate.exe"; p.StartInfo.UseShellExecute = true; p.StartInfo.Arguments = param; p.Start(); } } }