Skip to main content

ProcessRunner

A class in Root.Township, the global namespace.

Runs an external program hidden, logs its output with a prefix, and lets the caller await its exit.

Constructors​

MemberWhat it is
ProcessRunner(string processPrefix)Creates a ProcessRunner from processPrefix.

Fields​

4 private and internal fields
MemberWhat it is
private TaskCompletionSource<bool> handleProcessCompletionCompletes when the program exits.
private static readonly Logger LoggerNLog logger for the program's output.
private Process processThe running program.
private readonly string processPrefixText put in front of every logged line.

Methods​

MemberWhat it is
void Dispose()Disposes the process.
async Task StartProcess(string file, string arguments)Starts the program with arguments and waits until it exits.
protected override void Finalize()Disposes the process if Dispose wasn't called.
4 private and internal methods
MemberWhat it is
private bool CompletedWithoutError()True if the exit code was 0.
private void LogOutput(object sender, DataReceivedEventArgs e)Logs each output line, as an error if it starts with error or unable, else as debug.
private void OnExit(object sender, EventArgs e)Completes the await, unhooks output and throws if the exit code wasn't 0. The throw is on the exit event, not to the awaiter.
private void ReleaseUnmanagedResources()Disposes the process if there is one.