Leggere in inglese

Condividi tramite


Dns.BeginResolve(String, AsyncCallback, Object) Metodo

Definizione

Attenzione

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

Attenzione

BeginResolve has been deprecated. Use BeginGetHostEntry instead.

Attenzione

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

Avvia una richiesta asincrona per risolvere un nome host DNS o un indirizzo IP in un'istanza di IPAddress.

[System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestCallback, object? stateObject);
[System.Obsolete("BeginResolve has been deprecated. Use BeginGetHostEntry instead.")]
public static IAsyncResult BeginResolve(string hostName, AsyncCallback? requestCallback, object? stateObject);
[System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static IAsyncResult BeginResolve(string hostName, AsyncCallback requestCallback, object stateObject);
[System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static IAsyncResult BeginResolve(string hostName, AsyncCallback requestCallback, object stateObject);
public static IAsyncResult BeginResolve(string hostName, AsyncCallback requestCallback, object stateObject);

Parametri

hostName
String

Nome DNS dell'host.

requestCallback
AsyncCallback

Delegato AsyncCallback cui fa riferimento il metodo da richiamare al completamento dell'operazione.

stateObject
Object

Oggetto definito dall'utente che contiene informazioni sull'operazione. Questo oggetto viene passato al delegato requestCallback al completamento dell'operazione.

Restituisce

Istanza di IAsyncResult che fa riferimento alla richiesta asincrona.

Attributi

Eccezioni

hostName è null.

Il chiamante non dispone delle autorizzazioni per accedere alle informazioni DNS.

Esempio

Nell'esempio seguente viene usato BeginResolve per risolvere un nome host DNS in un oggetto IPAddress.

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

Commenti

L'operazione asincrona BeginResolve deve essere completata chiamando il EndResolve metodo . In genere, il metodo viene richiamato dal requestCallback delegato.

Questo metodo non viene bloccato fino al completamento dell'operazione. Per bloccare fino al completamento dell'operazione, usare il Resolve metodo .

Per altre informazioni sull'uso del modello di programmazione asincrona, vedere Chiamata asincrona di metodi sincroni.

Nota

Questo membro genera informazioni di traccia quando si abilita la traccia di rete nell'applicazione. Per altre informazioni, vedere Traccia di rete in .NET Framework.

Si applica a

Prodotto Versioni (Obsoleto)
.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)

Vedi anche