Kill child process when parent process is killed

前端 未结 15 2677
轻奢々
轻奢々 2020-11-22 05:59

I\'m creating new processes using System.Diagnostics.Process class from my application.

I want this processes to be killed when/if my application has cr

15条回答
  •  梦如初夏
    2020-11-22 06:36

    call job.AddProcess better to do after start of the process:

    prc.Start();
    job.AddProcess(prc.Handle);
    

    When calling AddProcess before the terminate, child processes are not killed. (Windows 7 SP1)

    private void KillProcess(Process proc)
    {
        var job = new Job();
        job.AddProcess(proc.Handle);
        job.Close();
    }
    

提交回复
热议问题