我正在研究实现SSH.Net库的C#程序。该程序的功能之一允许通过SSH将命令发送到目标服务器,然后在文本字段中显示输出。
这可以正常工作,但是当输出响应很大时,我遇到了一个问题。
当前,所有输出都显示直到完成。我需要一种方法,例如显示30行,然后等待用户输入,显示接下来的30行。
我可以通过for循环和计数器轻松地将输出停止在30行,但是我不确定如何再次启动它,如何回到流读取器中的同一点?
var list = new List<string>();
string line;
output_textBox.Text = String.Empty;
while (!asynch.IsCompleted)
{
using (StreamReader sr = new StreamReader(cmd.OutputStream))
{
while ((line = sr.ReadLine()) != null)
{
list.Add(line);
Console.WriteLine(line);
}
}
}
谢谢
编辑
在下面使用它。
using (StreamReader sr = new StreamReader(cmd.OutputStream))
{
while (!sr.EndOfStream)
{
while (line_count < 100 && (line = sr.ReadLine()) != null)
{
Console.SetOut(new TextBoxWriter(output_textBox));
Console.WriteLine(line);
line_count++;
}
MessageBox.Show("OK to continue");
line_count = 0;
}
最佳答案
看来您正在使用并行编程。您可以编写两个函数,分别是Producer和Consumer。例如,生产者将连续阅读您的文本并将其放入内存列表中,而消费者将在您适当的时间间隔从列表中消费(并删除消费的行)。
关于c# - C#在 'x'行数之后暂停streamreader输出,然后继续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32348764/