private void KillNodeProcess() { lock (_syncObject) { if (_nodeProcess != null) { _nodeProcess.Kill(); } } }
private async Task <int> WaitAndKillOnCancelAsync(ProcessOutput processOutput, CancellationToken ct) { var tcs = new TaskCompletionSource <int>(); processOutput.Exited += (o, e) => tcs.TrySetResult(0); try { if (processOutput.ExitCode == null) { tcs.RegisterForCancellation(ct).UnregisterOnCompletion(tcs.Task); await tcs.Task; } return((int)processOutput.ExitCode); } catch (OperationCanceledException) when(ct.IsCancellationRequested) { try { processOutput.Kill(); } catch (InvalidOperationException) { // Must have exited just as we were about to kill it } throw; } }