Fix two more System.Net async instead of sync calls (dotnet/corefx#37329)
authorStephen Toub <stoub@microsoft.com>
Wed, 1 May 2019 16:45:35 +0000 (12:45 -0400)
committerGitHub <noreply@github.com>
Wed, 1 May 2019 16:45:35 +0000 (12:45 -0400)
These were written as sync-over-async before the sync APIs were available.  Now that the sync APIs are available, use them.

Commit migrated from https://github.com/dotnet/corefx/commit/5cb6b8b340aafc3d7c6afe212fab103ef697fa02

src/libraries/System.Net.Sockets/src/System/Net/Sockets/UDPClient.cs
src/libraries/System.Net.WebProxy/src/System/Net/WebProxy.cs

index cb2d2fb..0cbc27f 100644 (file)
@@ -327,7 +327,7 @@ namespace System.Net.Sockets
             IPEndPoint ipEndPoint = null;
             if (hostname != null && port != 0)
             {
-                IPAddress[] addresses = Dns.GetHostAddressesAsync(hostname).GetAwaiter().GetResult();
+                IPAddress[] addresses = Dns.GetHostAddresses(hostname);
 
                 int i = 0;
                 for (; i < addresses.Length && !IsAddressFamilyCompatible(addresses[i].AddressFamily); i++)
index 325d82c..a97631f 100644 (file)
@@ -184,7 +184,7 @@ namespace System.Net
             // Perf note: The .NET Framework caches this and then uses network change notifications to track
             // whether the set should be recomputed.  We could consider doing the same if this is observed as
             // a bottleneck, but that tracking has its own costs.
-            IPAddress[] localAddresses = Dns.GetHostEntryAsync(Dns.GetHostName()).GetAwaiter().GetResult().AddressList; // TODO: Use synchronous GetHostEntry when available
+            IPAddress[] localAddresses = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
             for (int i = 0; i < localAddresses.Length; i++)
             {
                 if (ipAddress.Equals(localAddresses[i]))