在Winforms c#中,StreamReader花了很长时间来获取SSHclient命令执行输出

本文关键字:获取 长时间 SSHclient 命令 输出 执行 Winforms StreamReader | 更新日期: 2023-09-27 18:16:46

使用sshclient执行命令后,输出将同时写入文本框。这里我在执行命令后使用streamreader。我的要求是在执行的时候,我需要把输出写到RichTextbox。

var error = string.Empty;
using (var client = new SshClient(host, SuspenseConstants.Port, user, passwrd))
{
    client.Connect();
    var command = client.RunCommand(script);
    var reader = new StreamReader(command.ExtendedOutputStream);
    while(!reader.EndOfStream)
    {
        var output = reader.ReadLine();
        reprocessResult.txtReprocessingDetail.AppendText(output + " 'r'n");
        reprocessResult.txtReprocessingDetail.Update();
        if (output != null && output.Contains("ERROR"))
        {
            error = output;
        }
        Thread.Sleep(100);
}

在Winforms c#中,StreamReader花了很长时间来获取SSHclient命令执行输出

你逐行阅读,每行阅读后有100毫秒的睡眠,这就是为什么它需要时间。无其他原因