C#SSH命令执行
我需要在我的应用程序上提供一个小帮助。当我按按钮时,应用程序会冻结,直到SSH完成发送的commnand。我尝试了从 c#应用程序冻结但是,当我尝试使用task> task.factory时,我尝试了解决方案。 startnew(()...
我没有控制台的输出。有我的代码:
var cmd = SSH.CreateCommand("apt update && apt upgrade -y");
var asynch = cmd.BeginExecute();
var reader = new StreamReader(cmd.OutputStream);
while (!asynch.IsCompleted)
{
var result = reader.ReadToEnd();
if (string.IsNullOrEmpty(result))
continue;
Console.Write(result);
}
cmd.EndExecute(asynch);
有人与它有关系吗?
i need a small help with my app. When I press the button the app freezes until ssh complete the commnand which was sent. I tried solution from C# application freezes but when I tried to use Task.Factory.StartNew(()...
i dont have a output in console. There is my code:
var cmd = SSH.CreateCommand("apt update && apt upgrade -y");
var asynch = cmd.BeginExecute();
var reader = new StreamReader(cmd.OutputStream);
while (!asynch.IsCompleted)
{
var result = reader.ReadToEnd();
if (string.IsNullOrEmpty(result))
continue;
Console.Write(result);
}
cmd.EndExecute(asynch);
Does anyone have anything to do with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能正在使用wir循环阻止您的GUI线程。
您需要运行代码异步。
You are probably blocking your GUI thread with your while loop.
You need to run your code async.