From 25bb64fde9aa33c138eafc2c130ad4e82bbfe57d Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Mon, 30 Oct 2017 12:20:41 +0100 Subject: [PATCH] Avoid using Result and Wait() on Task. --- src/Renci.SshNet/Abstractions/DnsAbstraction.cs | 14 ++++++++------ src/Renci.SshNet/Abstractions/ThreadAbstraction.cs | 2 +- src/Renci.SshNet/Shell.cs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/DnsAbstraction.cs b/src/Renci.SshNet/Abstractions/DnsAbstraction.cs index cd9a399bd..0af35aeed 100644 --- a/src/Renci.SshNet/Abstractions/DnsAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/DnsAbstraction.cs @@ -2,18 +2,20 @@ using System.Net; using System.Net.Sockets; -#if FEATURE_DEVICEINFORMATION_APM +#if FEATURE_DNS_SYNC +#elif FEATURE_DNS_APM +using Renci.SshNet.Common; +#elif FEATURE_DNS_TAP +#elif FEATURE_DEVICEINFORMATION_APM using System.Collections.Generic; using System.Linq; using System.Threading; using Microsoft.Phone.Net.NetworkInformation; -#endif // FEATURE_DEVICEINFORMATION_APM - -#if FEATURE_DATAGRAMSOCKET +#elif FEATURE_DATAGRAMSOCKET using System.Collections.Generic; using Windows.Networking; using Windows.Networking.Sockets; -#endif // FEATURE_DATAGRAMSOCKET +#endif namespace Renci.SshNet.Abstractions { @@ -41,7 +43,7 @@ public static IPAddress[] GetHostAddresses(string hostNameOrAddress) throw new SshOperationTimeoutException("Timeout resolving host name."); return Dns.EndGetHostAddresses(asyncResult); #elif FEATURE_DNS_TAP - return Dns.GetHostAddressesAsync(hostNameOrAddress).Result; + return Dns.GetHostAddressesAsync(hostNameOrAddress).GetAwaiter().GetResult(); #else IPAddress address; if (IPAddress.TryParse(hostNameOrAddress, out address)) diff --git a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs index 471750306..ee21ec7ef 100644 --- a/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs +++ b/src/Renci.SshNet/Abstractions/ThreadAbstraction.cs @@ -13,7 +13,7 @@ public static void Sleep(int millisecondsTimeout) #if FEATURE_THREAD_SLEEP System.Threading.Thread.Sleep(millisecondsTimeout); #elif FEATURE_THREAD_TAP - System.Threading.Tasks.Task.Delay(millisecondsTimeout).Wait(); + System.Threading.Tasks.Task.Delay(millisecondsTimeout).GetAwaiter().GetResult(); #else #error Suspend of the current thread is not implemented. #endif diff --git a/src/Renci.SshNet/Shell.cs b/src/Renci.SshNet/Shell.cs index e2e2b5587..c508be896 100644 --- a/src/Renci.SshNet/Shell.cs +++ b/src/Renci.SshNet/Shell.cs @@ -135,7 +135,7 @@ public void Start() if (WaitHandle.WaitAny(new[] {readWaitHandle, _channelClosedWaitHandle}) == 0) { - var read = readTask.Result; + var read = readTask.GetAwaiter().GetResult(); _channel.SendData(buffer, 0, read); continue; }