private static void KillChildProcesses(int parentId, ProcessWithParentId[] currentlyRunningProcs) { foreach (ProcessWithParentId proc in currentlyRunningProcs) { if ((proc.ParentId > 0) && (proc.ParentId == parentId)) { KillProcessAndChildProcesses(proc.OriginalProcessInstance, currentlyRunningProcs); } } }
public static ProcessWithParentId[] Construct(Process[] originalProcCollection) { ProcessWithParentId[] result = new ProcessWithParentId[originalProcCollection.Length]; for (int index = 0; index < originalProcCollection.Length; index++) { result[index] = new ProcessWithParentId(originalProcCollection[index]); } return result; }
/// <summary> /// Kills the process tree (process + associated child processes) /// </summary> /// <param name="processToKill"></param> /// <param name="currentlyRunningProcs"></param> private static void KillProcessAndChildProcesses(Process processToKill, ProcessWithParentId[] currentlyRunningProcs) { try { // Kill children first.. int processId = processToKill.Id; KillChildProcesses(processId, currentlyRunningProcs); // kill the parent after children terminated. processToKill.Kill(); } catch (System.ComponentModel.Win32Exception) { try { // For processes running in an NTVDM, trying to kill with // the original handle fails with a Win32 error, so we'll // use the ID and try to get a new handle... Process newHandle = Process.GetProcessById(processToKill.Id); // If the process was not found, we won't get here... newHandle.Kill(); } catch (Exception e) // ignore non-severe exceptions { CommandProcessorBase.CheckForSevereException(e); } } catch (Exception e) // ignore non-severe exceptions { CommandProcessorBase.CheckForSevereException(e); } }
private static void KillProcessAndChildProcesses(Process processToKill, ProcessWithParentId[] currentlyRunningProcs) { try { KillChildProcesses(processToKill.Id, currentlyRunningProcs); processToKill.Kill(); } catch (Win32Exception) { try { Process.GetProcessById(processToKill.Id).Kill(); } catch (Exception exception) { CommandProcessorBase.CheckForSevereException(exception); } } catch (Exception exception2) { CommandProcessorBase.CheckForSevereException(exception2); } }