共用方式為


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 資訊的非同步要求。

public:
 static System::Net::IPHostEntry ^ EndResolve(IAsyncResult ^ asyncResult);
[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);
[System.Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")]
public static System.Net.IPHostEntry EndResolve (IAsyncResult asyncResult);
[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);
public static System.Net.IPHostEntry EndResolve (IAsyncResult asyncResult);
[<System.Obsolete("EndResolve is obsoleted for this type, please use EndGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
static member EndResolve : IAsyncResult -> System.Net.IPHostEntry
[<System.Obsolete("EndResolve has been deprecated. Use EndGetHostEntry instead.")>]
static member EndResolve : IAsyncResult -> System.Net.IPHostEntry
[<System.Obsolete("EndResolve is obsoleted for this type, please use EndGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member EndResolve : IAsyncResult -> System.Net.IPHostEntry
static member EndResolve : IAsyncResult -> System.Net.IPHostEntry
Public Shared Function EndResolve (asyncResult As IAsyncResult) As IPHostEntry

參數

asyncResult
IAsyncResult

IAsyncResult 執行個體,呼叫 BeginResolve(String, AsyncCallback, Object) 方法時傳回。

傳回

IPHostEntry 物件,包含關於主機的 DNS 資訊。

屬性

例外狀況

asyncResultnull

範例

下列範例會結束 DNS 主機資訊的異步要求。

public ref class DnsBeginGetHostByName
{
public:
   static System::Threading::ManualResetEvent^ allDone = nullptr;
   ref class RequestState
   {
   public:
      IPHostEntry^ host;
      RequestState()
      {
         host = nullptr;
      }
   };

   static void RespCallback( IAsyncResult^ ar )
   {
      try
      {
         // Convert the IAsyncResult* Object* to a RequestState Object*.
         RequestState^ tempRequestState = dynamic_cast<RequestState^>(ar->AsyncState);
         
         // End the asynchronous request.
         tempRequestState->host = Dns::EndResolve( ar );
         allDone->Set();
      }
      catch ( ArgumentNullException^ e ) 
      {
         Console::WriteLine( "ArgumentNullException caught!!!" );
         Console::WriteLine( "Source : {0}", e->Source );
         Console::WriteLine( "Message : {0}", e->Message );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Exception caught!!!" );
         Console::WriteLine( "Source : {0}", e->Source );
         Console::WriteLine( "Message : {0}", e->Message );
      }
   }
};

int main()
{
   DnsBeginGetHostByName::allDone = gcnew ManualResetEvent( false );
   
   // Create an instance of the RequestState class.
   DnsBeginGetHostByName::RequestState^ myRequestState =
      gcnew DnsBeginGetHostByName::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",
      gcnew AsyncCallback( DnsBeginGetHostByName::RespCallback ), myRequestState );
   
   // Wait until asynchronous call completes.
   DnsBeginGetHostByName::allDone->WaitOne();
   Console::WriteLine( "Host name : {0}", 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 ] );
}
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);
     }
   }
}
Class DnsBeginGetHostByName
    
    Class RequestState
        Public host As IPHostEntry
        
        Public Sub New()
            host = Nothing
        End Sub
    End Class
    
    
    Public Shared Sub Main()
     Try
        ' Create an instance of the RequestState class.
        Dim myRequestState As New RequestState()
        
        ' Begin an asynchronous request for information such as the host name, IP addresses, 
        ' or aliases for the specified URI.
        Dim asyncResult As IAsyncResult = CType(Dns.BeginResolve("www.contoso.com", AddressOf RespCallback, myRequestState),IAsyncResult)

        ' Wait until asynchronous call completes.
        While asyncResult.IsCompleted <> True
        End While
        
        Console.WriteLine(("Host name : " + myRequestState.host.HostName))
        Console.WriteLine(ControlChars.Cr + "IP address list : ")
        Dim index As Integer
        For index = 0 To myRequestState.host.AddressList.Length - 1
            Console.WriteLine(myRequestState.host.AddressList(index))
        Next index
        Console.WriteLine(ControlChars.Cr + "Aliases : ")

        For index = 0 To myRequestState.host.Aliases.Length - 1
            Console.WriteLine(myRequestState.host.Aliases(index))
        Next index
    catch e as Exception
            Console.WriteLine("Exception caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
    End Try
    End Sub
    
    
    Private Shared Sub RespCallback(ar As IAsyncResult)
        Try
            ' Convert the IAsyncResult object to a RequestState object.
            Dim tempRequestState As RequestState = CType(ar.AsyncState, RequestState)

            ' End the asynchronous request.
            tempRequestState.host = Dns.EndResolve(ar)
            Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
            Catch e As Exception
            Console.WriteLine("Exception caught!!!")
            Console.WriteLine(("Source : " + e.Source))
            Console.WriteLine(("Message : " + e.Message))
        End Try
    End Sub

備註

這個方法會封鎖直到作業完成為止。

Ipv6Element.Enabled如果 設定為 true,則Aliases傳回之 實例的 IPHostEntry 屬性不會由這個方法填入,而且一律為空白。

若要同步執行這項作業,請使用 Resolve 方法。

注意

當您在應用程式中啟用網路追蹤時,此成員會發出追蹤資訊。 如需詳細資訊,請參閱 .NET Framework 中的網路追蹤

適用於

另請參閱