/// <summary> /// 寻找符合条件的进程。 /// </summary> /// <param name="findProcessesParam"></param> /// <returns></returns> public static Process[] FindProcesses(FindProcessesParam findProcessesParam) { Process[] processes = Process.GetProcesses(); //processes[0]. if (!string.IsNullOrEmpty(findProcessesParam.ProcessName)) { processes = processes.Where(a => a.ProcessName.Contains(findProcessesParam.ProcessName)).ToArray(); } if (findProcessesParam.HasMainWindowTitle.HasValue) { processes = processes.Where(a => findProcessesParam.HasMainWindowTitle.Value ? !string.IsNullOrEmpty(a.MainWindowTitle) : string.IsNullOrEmpty(a.MainWindowTitle)).ToArray(); } if (!string.IsNullOrEmpty(findProcessesParam.MainWindowTitle)) { processes = processes.Where(a => a.MainWindowTitle.Contains(findProcessesParam.MainWindowTitle)).ToArray(); } //DateTime t=processes[0].StartTime; //if (findProcessesParam.StartTimeAsc) //{ // processes = processes.OrderBy(a=>a.StartTime).ToArray(); //} //if (findProcessesParam.StartTimeDesc) //{ // processes = processes.OrderByDescending(a => a.StartTime).ToArray(); //} return(processes); }
/// <summary> /// 寻找符合条件的第一个进程 /// </summary> /// <param name="findProcessesParam"></param> /// <returns></returns> public static Process FirstProcess(FindProcessesParam findProcessesParam) => FindProcesses(findProcessesParam)[0];