- for (int i = 0; i < procs.Length; i++) {
- /* Ignore case */
- if (String.Compare (processName,
- procs [i].ProcessName,
- true) == 0) {
- proclist.Add (procs [i]);
+ ArrayList proclist = new ArrayList (pids.Length);
+ for (int i = 0; i < pids.Length; i++) {
+ try {
+ Process p = GetProcessById (pids [i]);
+ if (String.Compare (processName, p.ProcessName, true) == 0)
+ proclist.Add (p);
+ } catch (SystemException) {
+ /* The process might exit
+ * between
+ * GetProcesses_internal and
+ * GetProcessById
+ */