A basic library to launch Processes as Cancellable Tasks
using System.Diagnostics;
// ...
var process = new ProcessStartInfo("cmd.exe", "/c Hello World!");
var result = await process.StartAsync();
result.Should().Be(0);
using System.Diagnostics;
// ...
try
{
var process = new ProcessStartInfo("cmd.exe", "/c ping -t 127.0.0.1");
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMinutes(1));
await process.StartAsync(cts.Token);
}
catch (TaskCanceledException)
{
// One minute later
}
using System.Diagnostics;
// ...
var output = new StringBuilder();
var psi = new ProcessStartInfo("cmd.exe", @"/c tree \");
await psi.StartAsync((string line) => output.AppendLine(line)).ConfigureAwait(false);
return output.ToString();