private void StartProcess() { if (TrySetCanceled() || _tcs.Task.IsCompleted) { return; } _process.StartInfo.UseShellExecute = false; _process.StartInfo.RedirectStandardOutput = true; _process.StartInfo.RedirectStandardError = true; _process.OutputDataReceived += (sender, args) => OnDataReceived(args, _outputData, _outputTcs); _process.ErrorDataReceived += (sender, args) => OnDataReceived(args, _errorData, _errorTcs); _process.Exited += (o, e) => _ = HandleExitAsync(); _timeoutCts?.CancelAfter(_timeout); if (!_process.Start()) { TrySetException(new InvalidOperationException($"Failed to start process '{_process.StartInfo.FileName}'")); } _process.BeginOutputReadLine(); _process.BeginErrorReadLine(); _ctRegistration = _cancellationToken.Register(HandleCancel, false); }