public async Task <string> InvokeReadLineAsync(bool isCommandLine, CancellationToken cancellationToken)
        {
            _readLineCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            var localTokenSource = _readLineCancellationSource;

            if (localTokenSource.Token.IsCancellationRequested)
            {
                throw new TaskCanceledException();
            }

            try
            {
                if (!isCommandLine)
                {
                    return(await _consoleReadLine.InvokeLegacyReadLineAsync(
                               false,
                               _readLineCancellationSource.Token));
                }

                var result = (await _powerShellContext.ExecuteCommandAsync <string>(
                                  new PSCommand()
                                  .AddScript(ReadLineScript)
                                  .AddArgument(_readLineCancellationSource.Token),
                                  null,
                                  new ExecutionOptions()
                {
                    WriteErrorsToHost = false,
                    WriteOutputToHost = false,
                    InterruptCommandPrompt = false,
                    AddToHistory = false,
                    IsReadLine = isCommandLine
                }))
                             .FirstOrDefault();

                return(cancellationToken.IsCancellationRequested
                    ? string.Empty
                    : result);
            }
            finally
            {
                _readLineCancellationSource = null;
            }
        }
 public async Task <string> InvokeReadLineAsync(bool isCommandLine, CancellationToken cancellationToken)
 {
     return(await _legacyReadLine.InvokeLegacyReadLineAsync(isCommandLine, cancellationToken));
 }