Прочитать на английском

Поделиться через


Dns.EndResolve(IAsyncResult) Метод

Определение

Внимание!

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

Внимание!

EndResolve has been deprecated. Use EndGetHostEntry instead.

Внимание!

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

Завершает асинхронный запрос сведений DNS.

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 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. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.IPHostEntry EndResolve(IAsyncResult asyncResult);
C#
public static System.Net.IPHostEntry EndResolve(IAsyncResult asyncResult);

Параметры

asyncResult
IAsyncResult

Экземпляр IAsyncResult, возвращенный вызовом метода BeginResolve(String, AsyncCallback, Object).

Возвращаемое значение

Объект IPHostEntry, содержащий сведения DNS об узле.

Атрибуты

Исключения

asyncResult имеет значение null.

Примеры

В следующем примере завершается асинхронный запрос сведений об узле DNS.

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);
     }
   }
}

Комментарии

Этот метод блокируется до завершения операции.

Ipv6Element.Enabled Если для задано значение true, Aliases свойство возвращаемого IPHostEntry экземпляра не заполняется этим методом и всегда будет пустым.

Чтобы выполнить эту операцию синхронно, используйте Resolve метод .

Примечание

Этот элемент выдает сведения трассировки при включении трассировки сети в приложении. Дополнительные сведения см. в статье Трассировка сети в .NET Framework.

Применяется к

Продукт Версии (Устарело)
.NET (Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9)
.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)

См. также раздел