Skip to content

Commit

Permalink
Avoid using Result and Wait() on Task<T>.
Browse files Browse the repository at this point in the history
  • Loading branch information
drieseng committed Oct 30, 2017
1 parent 95f0f22 commit 25bb64f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/Renci.SshNet/Abstractions/DnsAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Abstractions/ThreadAbstraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 25bb64f

Please sign in to comment.