Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.TrySetResult(SSHCommandResult) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
Source : SSHClientExtensions.cs
with MIT License
from btcpayserver
with MIT License
from btcpayserver
public static Task<SSHCommandResult> RunBash(this SshClient sshClient, string command, TimeSpan? timeout = null)
{
if (sshClient == null)
throw new ArgumentNullException(nameof(sshClient));
if (command == null)
throw new ArgumentNullException(nameof(command));
command = $"bash -c '{command.EscapeSingleQuotes()}'";
var sshCommand = sshClient.CreateCommand(command);
if (timeout is TimeSpan v)
sshCommand.CommandTimeout = v;
var tcs = new TaskCompletionSource<SSHCommandResult>(TaskCreationOptions.RunContinuationsAsynchronously);
new Thread(() =>
{
try
{
sshCommand.BeginExecute(ar =>
{
try
{
sshCommand.EndExecute(ar);
tcs.TrySetResult(CreateSSHCommandResult(sshCommand));
}
catch (Exception ex)
{
tcs.TrySetException(ex);
}
finally
{
sshCommand.Dispose();
}
});
}
catch (Exception ex) { tcs.TrySetException(ex); }
})
{ IsBackground = true }.Start();
return tcs.Task;
}