A small .NET library for grouping processes in a Windows Job Object. Disposing the job terminates every process assigned to it.
Note: Starting with .NET 11, if you only need a newly started child process to terminate when its parent process exits, use the built-in
ProcessStartInfo.KillOnParentExitproperty instead.
usingSystem.Diagnostics;usingWindowsJobAPI;usingProcessprocess=Process.Start(newProcessStartInfo{FileName="cmd.exe",UseShellExecute=false,})??thrownewInvalidOperationException("Unable to start the process.");usingJobObjectjob=new();if(!job.AddProcess(process)){thrownewInvalidOperationException("Unable to add the process to the job.");}// Disposing job terminates process and any child processes in the same job.