按下执行底部后,ssh命令被发送并执行完美但在此之后,应用程序冻结,我无法按任何其他按钮。这是代码:
private void timer1_Tick(object sender, EventArgs e)
{
try
{
SshClient cSSH = new SshClient("ip", 22, "root", "pass");
cSSH.Connect();
SshCommand x = cSSH.RunCommand("ssh command");
cSSH.Disconnect();
cSSH.Dispose();
}
catch (Exception error)
{
MessageBox.Show("Error:" + error);
}
}
修改
代码停留在以下行:
SshClient cSSH = new SshClient("ip", 22, "root", "pass");
答案 0 :(得分:1)
您可以使用任务:
private void timer1_Tick(object sender, EventArgs e)
{
Task.Factory.StartNew(() =>
{
using (SshClient cSSH = new SshClient("ip", 22, "root", "pass")
{
cSSH.Connect();
SshCommand x = cSSH.RunCommand("ssh command");
}
});
}