Kill child process when parent process is killed

前端 未结 15 2653
轻奢々
轻奢々 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:31

    Solution that worked for me:

    When creating process add tag process.EnableRaisingEvents = true;:

    csc = new Process();
    csc.StartInfo.UseShellExecute = false;
    csc.StartInfo.CreateNoWindow = true;
    csc.StartInfo.FileName = Path.Combine(HLib.path_dataFolder, "csc.exe");
    csc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    csc.StartInfo.ErrorDialog = false;
    csc.StartInfo.RedirectStandardInput = true;
    csc.StartInfo.RedirectStandardOutput = true;
    csc.EnableRaisingEvents = true;
    csc.Start();
    

提交回复
热议问题