Läs på engelska Redigera

Dela via


Dns.EndResolve(IAsyncResult) Method

Definition

Caution

EndResolve has been deprecated. Use EndGetHostEntry instead.

Caution

EndResolve is obsoleted for this type, please use EndGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202

Caution

EndResolve is obsoleted for this type, please use EndGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202

Ends an asynchronous request for DNS information.

C#
[System.Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")]
public static System.Net.IPHostEntry EndResolve(IAsyncResult asyncResult);
C#
[System.Obsolete("EndResolve is obsoleted for this type, please use EndGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.IPHostEntry EndResolve(IAsyncResult asyncResult);
C#
[System.Obsolete("EndResolve is obsoleted for this type, please use EndGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.IPHostEntry EndResolve(IAsyncResult asyncResult);
C#
public static System.Net.IPHostEntry EndResolve(IAsyncResult asyncResult);

Parameters

asyncResult
IAsyncResult

An IAsyncResult instance that is returned by a call to the BeginResolve(String, AsyncCallback, Object) method.

Returns

An IPHostEntry object that contains DNS information about a host.

Attributes

Exceptions

asyncResult is null.

Examples

The following example ends an asynchronous request for DNS host information.

C#
class DnsBeginGetHostByName
{
   public static System.Threading.ManualResetEvent allDone = null;

   class RequestState
   {
      public IPHostEntry host;
      public RequestState()
      {
         host = null;
      }
   }

   public static void Main()
   {
     allDone = new ManualResetEvent(false);
     // Create an instance of the RequestState class.
     RequestState myRequestState = new RequestState();

     // Begin an asynchronous request for information like host name, IP addresses, or
     // aliases for specified the specified URI.
     IAsyncResult asyncResult = Dns.BeginResolve("www.contoso.com", new AsyncCallback(RespCallback), myRequestState );

     // Wait until asynchronous call completes.
     allDone.WaitOne();
     Console.WriteLine("Host name : " + myRequestState.host.HostName);
     Console.WriteLine("\nIP address list : ");
     for(int index=0; index < myRequestState.host.AddressList.Length; index++)
     {
       Console.WriteLine(myRequestState.host.AddressList[index]);
     }
     Console.WriteLine("\nAliases : ");
     for(int index=0; index < myRequestState.host.Aliases.Length; index++)
     {
       Console.WriteLine(myRequestState.host.Aliases[index]);
     }
   }

   private static void RespCallback(IAsyncResult ar)
   {
     try
     {
       // Convert the IAsyncResult object to a RequestState object.
       RequestState tempRequestState = (RequestState)ar.AsyncState;
       // End the asynchronous request.
       tempRequestState.host = Dns.EndResolve(ar);
       allDone.Set();
     }
       catch(ArgumentNullException e)
     {
       Console.WriteLine("ArgumentNullException caught!!!");
       Console.WriteLine("Source : " + e.Source);
       Console.WriteLine("Message : " + e.Message);
     }
     catch(Exception e)
     {
       Console.WriteLine("Exception caught!!!");
       Console.WriteLine("Source : " + e.Source);
       Console.WriteLine("Message : " + e.Message);
     }
   }
}

Remarks

This method blocks until the operation is complete.

If the Ipv6Element.Enabled is set to true, the Aliases property of the IPHostEntry instance returned is not populated by this method and will always be empty.

To perform this operation synchronously, use the Resolve method.

Anteckning

This member emits trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

Applies to

Produkt Versioner (Föråldrad)
.NET (Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10)
.NET Framework 1.1 (2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1)
.NET Standard (2.0, 2.1)

See also