Closed
Description
When calling CancelAsync
for a process started by BeginExecute
, the process is not canceled and the result of the command cannot be retrieved.
With enough time for executing the command and without CancelAsync
everything works fine:
using (SshClient client = new SshClient(host, username, password))
{
client.Connect();
using (SshCommand command = client.CreateCommand("sleep 10; echo run"))
{
IAsyncResult task = command.BeginExecute();
Thread.Sleep(15000);
//command.CancelAsync();
var result = command.EndExecute(task);
System.Console.WriteLine(result);
}
client.Disconnect();
}
After 15s, the following correctly appears in the console and the execution finishes:
run
If I reduce the sleep to 5s, and uncomment the CancelAsync
:
using (SshClient client = new SshClient(host, username, password))
{
client.Connect();
using (SshCommand command = client.CreateCommand("sleep 10; echo run"))
{
IAsyncResult task = command.BeginExecute();
Thread.Sleep(5000);
command.CancelAsync();
var result = command.EndExecute(task);
System.Console.WriteLine(result);
}
client.Disconnect();
}
The process gets blocked at EndExecute
instruction, it doesn't finish even though the command hasn't been canceled and it finishes after 10s from the beginning.
Metadata
Metadata
Assignees
Labels
No labels