Extension methods for System.Diagnostics.Process that add async-friendly waiting and cross-platform process-tree termination.
public static class ProcessExtensions
void KillTree(this Process process)Summary: Synchronously terminates the process and any child processes it started, using a default 30-second timeout per spawned helper command. On Windows uses
taskkill /T /F; on other platforms usespgrep+kill -TERM.Parameters:
process- The root process whose tree should be terminated.
void KillTree(this Process process, TimeSpan timeout)Summary: Synchronously terminates the process and any child processes it started, using a default 30-second timeout per spawned helper command. On Windows uses
taskkill /T /F; on other platforms usespgrep+kill -TERM.Parameters:
process- The root process whose tree should be terminated.
Task KillTreeAsync(this Process process, CancellationToken cancellationToken = null)Summary: Asynchronously terminates the process and any child processes it started, using the default 30-second timeout per helper command.
Parameters:
process- The root process whose tree should be terminated.
cancellationToken- Token used to abort the kill operation early.Returns: A task that completes when the kill commands have finished.
Task KillTreeAsync(this Process process, TimeSpan timeout, CancellationToken cancellationToken = null)Summary: Asynchronously terminates the process and any child processes it started, using the default 30-second timeout per helper command.
Parameters:
process- The root process whose tree should be terminated.
cancellationToken- Token used to abort the kill operation early.Returns: A task that completes when the kill commands have finished.
Task WaitForExitAsync(this Process process, CancellationToken cancellationToken = null)