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

时间:2015-10-08 07:18:23

标签: c# winforms

使用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);
}

1 个答案:

答案 0 :(得分:0)

您正在逐行阅读并在每行读取后睡眠100毫秒,这就是为什么需要花费时间。没有其他原因