Dns.BeginGetHostEntry Methode

Definition

Löst einen Hostnamen oder eine IP-Adresse asynchron in eine IPHostEntry-Instanz auf.

Überlädt

BeginGetHostEntry(IPAddress, AsyncCallback, Object)

Löst eine IP-Adresse asynchron in eine IPHostEntry-Instanz auf.

BeginGetHostEntry(String, AsyncCallback, Object)

Löst einen Hostnamen oder eine IP-Adresse asynchron in eine IPHostEntry-Instanz auf.

BeginGetHostEntry(IPAddress, AsyncCallback, Object)

Löst eine IP-Adresse asynchron in eine IPHostEntry-Instanz auf.

public:
 static IAsyncResult ^ BeginGetHostEntry(System::Net::IPAddress ^ address, AsyncCallback ^ requestCallback, System::Object ^ stateObject);
public static IAsyncResult BeginGetHostEntry (System.Net.IPAddress address, AsyncCallback? requestCallback, object? stateObject);
public static IAsyncResult BeginGetHostEntry (System.Net.IPAddress address, AsyncCallback requestCallback, object stateObject);
static member BeginGetHostEntry : System.Net.IPAddress * AsyncCallback * obj -> IAsyncResult
Public Shared Function BeginGetHostEntry (address As IPAddress, requestCallback As AsyncCallback, stateObject As Object) As IAsyncResult

Parameter

address
IPAddress

Die aufzulösende IP-Adresse.

requestCallback
AsyncCallback

Ein AsyncCallback-Delegat, der auf die Methode verweist, die bei Abschluss des Vorgangs aufgerufen werden soll.

stateObject
Object

Ein benutzerdefiniertes Objekt, das Informationen über den Vorgang enthält. Dieses Objekt wird bei Abschluss des Vorgangs an den requestCallback-Delegaten übergeben.

Gibt zurück

IAsyncResult

Eine IAsyncResult-Instanz, die auf die asynchrone Anforderung verweist.

Ausnahmen

address ist null.

Beim Auflösen von address ist ein Fehler aufgetreten.

address ist keine gültige IP-Adresse.

Beispiele

Im folgenden Codebeispiel wird die BeginGetHostEntry Methode zum Auflösen einer IP-Adresse in eine IPHostEntry Instanz verwendet.

    // Signals when the resolve has finished.
public:
    static ManualResetEvent^ GetHostEntryFinished =
        gcnew ManualResetEvent(false);

    // define the state object for the callback. 
    // use hostName to correlate calls with the proper result.
    ref class ResolveState
    {
    public:
        String^ hostName;
        IPHostEntry^ resolvedIPs;

        ResolveState(String^ host)
        {
            hostName = host;
        }

        property IPHostEntry^ IPs 
        {
            IPHostEntry^ get()
            {
                return resolvedIPs;
            }

            void set(IPHostEntry^ IPs)
            {
                resolvedIPs = IPs;
            }
        }

        property String^ host 
        {
            String^ get()
            {
                return hostName;
            }

            void set(String^ host)
            {
                hostName = host;
            }
        }
    };

    // Record the IPs in the state object for later use.
    static void GetHostEntryCallback(IAsyncResult^ ar)
    {
        ResolveState^ ioContext = (ResolveState^)(ar->AsyncState);

        ioContext->IPs = Dns::EndGetHostEntry(ar);
        GetHostEntryFinished->Set();
    }


    // Determine the Internet Protocol(IP) addresses for this 
    // host asynchronously.
public:
    static void DoGetHostEntryAsync(String^ hostName)
    {
        GetHostEntryFinished->Reset();
        ResolveState^ ioContext = gcnew ResolveState(hostName);

        Dns::BeginGetHostEntry(ioContext->host,
            gcnew AsyncCallback(GetHostEntryCallback), ioContext);
        // Wait here until the resolve completes 
        // (the callback calls .Set())
        GetHostEntryFinished->WaitOne();

        Console::WriteLine("EndGetHostEntry({0}) returns:", ioContext->host);
      
        for (int i = 0; i < ioContext->IPs->AddressList->Length; i++)
        {
            Console::WriteLine("    {0}", ioContext->IPs->AddressList[i]->ToString());
        }

//      for each (IPAddress^ address in ioContext->IPs)
//      {
//          Console::WriteLine("{0} ", address);
//      }
    }
// Signals when the resolve has finished.
public static ManualResetEvent GetHostEntryFinished =
    new ManualResetEvent(false);

// Define the state object for the callback.
// Use hostName to correlate calls with the proper result.
public class ResolveState
{
    string hostName;
    IPHostEntry resolvedIPs;

    public ResolveState(string host)
    {
        hostName = host;
    }

    public IPHostEntry IPs
    {
        get { return resolvedIPs; }
        set { resolvedIPs = value; }
    }

    public string host
    {
        get { return hostName; }
        set { hostName = value; }
    }
}

// Record the IPs in the state object for later use.
public static void GetHostEntryCallback(IAsyncResult ar)
{
    ResolveState ioContext = (ResolveState)ar.AsyncState;
    ioContext.IPs = Dns.EndGetHostEntry(ar);
    GetHostEntryFinished.Set();
}

// Determine the Internet Protocol (IP) addresses for
// this host asynchronously.
public static void DoGetHostEntryAsync(string hostname)
{
    GetHostEntryFinished.Reset();
    ResolveState ioContext= new ResolveState(hostname);

    Dns.BeginGetHostEntry(ioContext.host,
        new AsyncCallback(GetHostEntryCallback), ioContext);

    // Wait here until the resolve completes (the callback
    // calls .Set())
    GetHostEntryFinished.WaitOne();

    Console.WriteLine("EndGetHostEntry({0}) returns:", ioContext.host);

    foreach (IPAddress address in ioContext.IPs.AddressList)
    {
        Console.WriteLine($"    {address}");
    }
}
' Signals when the resolve has finished.
Dim Shared GetHostEntryFinished As ManualResetEvent = New ManualResetEvent(False)

' Define the state object for the callback. 
' Use hostName to correlate calls with the proper result.
Class ResolveState
    
    Dim hostName As String
    Dim resolvedIPs As IPHostEntry

    Public Sub New(host As String)
        hostName = host
    End Sub

    Public Property IPs AS IPHostEntry
        Get
            Return resolvedIPs
        End Get
        Set
            resolvedIPs = value
        End Set
    End Property

    Public Property host As String
        Get
            Return hostName
        End Get
        Set
            hostName = value
        End Set
    End Property

End Class

' Record the IPs in the state object for later use.
Shared Sub GetHostEntryCallback(ar As IAsyncResult)

    Dim ioContext As ResolveState = ar.AsyncState

    ioContext.IPs = Dns.EndGetHostEntry(ar)
    GetHostEntryFinished.Set()

End Sub

' Determine the Internet Protocol (IP) addresses for 
' this host asynchronously.
Shared Sub DoGetHostEntryAsync(hostname As String)
    
    GetHostEntryFinished.Reset()
    Dim ioContext As ResolveState = New ResolveState(hostname)

    Dns.BeginGetHostEntry(ioContext.host,AddressOf GetHostEntryCallback, ioContext)

    ' Wait here until the resolve completes (the callback 
    ' calls .Set())
    GetHostEntryFinished.WaitOne()

    Console.WriteLine($"EndGetHostEntry({ioContext.host}) returns:")

    Dim addresses As IPAddress() = ioContext.IPs.AddressList

    Dim index As Integer
    For index = 0 To addresses.Length - 1
        Console.WriteLine($"    {addresses(index)}")
    Next index

End Sub

Hinweise

Die BeginGetHostEntry Methode ruft asynchron einen DNS-Server für die IP-Adressen und Aliase ab, die einer IP-Adresse zugeordnet sind.

Hinweis Dieses Element sendet Ablaufverfolgungsinformationen, wenn Sie die Netzwerkablaufverfolgung in Ihrer Anwendung aktivieren. Weitere Informationen finden Sie unter "Netzwerkablaufverfolgung" im .NET Framework.

Der asynchrone BeginGetHostEntry Vorgang muss durch Aufrufen der EndGetHostEntry Methode abgeschlossen werden. In der requestCallback Regel wird die Methode vom Stellvertretung aufgerufen.

Diese Methode blockiert erst, wenn der Vorgang abgeschlossen ist. Um zu blockieren, bis der Vorgang abgeschlossen ist, verwenden Sie die GetHostEntry Methode.

Ausführliche Informationen zur Verwendung des asynchronen Programmiermodells finden Sie unter Aufrufen synchroner Methoden asynchron

Gilt für

BeginGetHostEntry(String, AsyncCallback, Object)

Löst einen Hostnamen oder eine IP-Adresse asynchron in eine IPHostEntry-Instanz auf.

public:
 static IAsyncResult ^ BeginGetHostEntry(System::String ^ hostNameOrAddress, AsyncCallback ^ requestCallback, System::Object ^ stateObject);
public static IAsyncResult BeginGetHostEntry (string hostNameOrAddress, AsyncCallback? requestCallback, object? stateObject);
public static IAsyncResult BeginGetHostEntry (string hostNameOrAddress, AsyncCallback requestCallback, object stateObject);
static member BeginGetHostEntry : string * AsyncCallback * obj -> IAsyncResult
Public Shared Function BeginGetHostEntry (hostNameOrAddress As String, requestCallback As AsyncCallback, stateObject As Object) As IAsyncResult

Parameter

hostNameOrAddress
String

Der aufzulösende Hostname oder die aufzulösende IP-Adresse.

requestCallback
AsyncCallback

Ein AsyncCallback-Delegat, der auf die Methode verweist, die bei Abschluss des Vorgangs aufgerufen werden soll.

stateObject
Object

Ein benutzerdefiniertes Objekt, das Informationen über den Vorgang enthält. Dieses Objekt wird bei Abschluss des Vorgangs an den requestCallback-Delegaten übergeben.

Gibt zurück

IAsyncResult

Eine IAsyncResult-Instanz, die auf die asynchrone Anforderung verweist.

Ausnahmen

hostNameOrAddress ist null.

hostNameOrAddress ist länger als 255 Zeichen.

Beim Auflösen von hostNameOrAddress ist ein Fehler aufgetreten.

hostNameOrAddress ist keine gültige IP-Adresse.

Beispiele

Im folgenden Codebeispiel wird die BeginGetHostEntry Methode zum Auflösen einer IP-Adresse in eine IPHostEntry Instanz verwendet.

    // Signals when the resolve has finished.
public:
    static ManualResetEvent^ GetHostEntryFinished =
        gcnew ManualResetEvent(false);

    // define the state object for the callback. 
    // use hostName to correlate calls with the proper result.
    ref class ResolveState
    {
    public:
        String^ hostName;
        IPHostEntry^ resolvedIPs;

        ResolveState(String^ host)
        {
            hostName = host;
        }

        property IPHostEntry^ IPs 
        {
            IPHostEntry^ get()
            {
                return resolvedIPs;
            }

            void set(IPHostEntry^ IPs)
            {
                resolvedIPs = IPs;
            }
        }

        property String^ host 
        {
            String^ get()
            {
                return hostName;
            }

            void set(String^ host)
            {
                hostName = host;
            }
        }
    };

    // Record the IPs in the state object for later use.
    static void GetHostEntryCallback(IAsyncResult^ ar)
    {
        ResolveState^ ioContext = (ResolveState^)(ar->AsyncState);

        ioContext->IPs = Dns::EndGetHostEntry(ar);
        GetHostEntryFinished->Set();
    }


    // Determine the Internet Protocol(IP) addresses for this 
    // host asynchronously.
public:
    static void DoGetHostEntryAsync(String^ hostName)
    {
        GetHostEntryFinished->Reset();
        ResolveState^ ioContext = gcnew ResolveState(hostName);

        Dns::BeginGetHostEntry(ioContext->host,
            gcnew AsyncCallback(GetHostEntryCallback), ioContext);
        // Wait here until the resolve completes 
        // (the callback calls .Set())
        GetHostEntryFinished->WaitOne();

        Console::WriteLine("EndGetHostEntry({0}) returns:", ioContext->host);
      
        for (int i = 0; i < ioContext->IPs->AddressList->Length; i++)
        {
            Console::WriteLine("    {0}", ioContext->IPs->AddressList[i]->ToString());
        }

//      for each (IPAddress^ address in ioContext->IPs)
//      {
//          Console::WriteLine("{0} ", address);
//      }
    }
// Signals when the resolve has finished.
public static ManualResetEvent GetHostEntryFinished =
    new ManualResetEvent(false);

// Define the state object for the callback.
// Use hostName to correlate calls with the proper result.
public class ResolveState
{
    string hostName;
    IPHostEntry resolvedIPs;

    public ResolveState(string host)
    {
        hostName = host;
    }

    public IPHostEntry IPs
    {
        get { return resolvedIPs; }
        set { resolvedIPs = value; }
    }

    public string host
    {
        get { return hostName; }
        set { hostName = value; }
    }
}

// Record the IPs in the state object for later use.
public static void GetHostEntryCallback(IAsyncResult ar)
{
    ResolveState ioContext = (ResolveState)ar.AsyncState;
    ioContext.IPs = Dns.EndGetHostEntry(ar);
    GetHostEntryFinished.Set();
}

// Determine the Internet Protocol (IP) addresses for
// this host asynchronously.
public static void DoGetHostEntryAsync(string hostname)
{
    GetHostEntryFinished.Reset();
    ResolveState ioContext= new ResolveState(hostname);

    Dns.BeginGetHostEntry(ioContext.host,
        new AsyncCallback(GetHostEntryCallback), ioContext);

    // Wait here until the resolve completes (the callback
    // calls .Set())
    GetHostEntryFinished.WaitOne();

    Console.WriteLine("EndGetHostEntry({0}) returns:", ioContext.host);

    foreach (IPAddress address in ioContext.IPs.AddressList)
    {
        Console.WriteLine($"    {address}");
    }
}
' Signals when the resolve has finished.
Dim Shared GetHostEntryFinished As ManualResetEvent = New ManualResetEvent(False)

' Define the state object for the callback. 
' Use hostName to correlate calls with the proper result.
Class ResolveState
    
    Dim hostName As String
    Dim resolvedIPs As IPHostEntry

    Public Sub New(host As String)
        hostName = host
    End Sub

    Public Property IPs AS IPHostEntry
        Get
            Return resolvedIPs
        End Get
        Set
            resolvedIPs = value
        End Set
    End Property

    Public Property host As String
        Get
            Return hostName
        End Get
        Set
            hostName = value
        End Set
    End Property

End Class

' Record the IPs in the state object for later use.
Shared Sub GetHostEntryCallback(ar As IAsyncResult)

    Dim ioContext As ResolveState = ar.AsyncState

    ioContext.IPs = Dns.EndGetHostEntry(ar)
    GetHostEntryFinished.Set()

End Sub

' Determine the Internet Protocol (IP) addresses for 
' this host asynchronously.
Shared Sub DoGetHostEntryAsync(hostname As String)
    
    GetHostEntryFinished.Reset()
    Dim ioContext As ResolveState = New ResolveState(hostname)

    Dns.BeginGetHostEntry(ioContext.host,AddressOf GetHostEntryCallback, ioContext)

    ' Wait here until the resolve completes (the callback 
    ' calls .Set())
    GetHostEntryFinished.WaitOne()

    Console.WriteLine($"EndGetHostEntry({ioContext.host}) returns:")

    Dim addresses As IPAddress() = ioContext.IPs.AddressList

    Dim index As Integer
    For index = 0 To addresses.Length - 1
        Console.WriteLine($"    {addresses(index)}")
    Next index

End Sub

Hinweise

Die BeginGetHostEntry Methode ruft einen DNS-Server für die IP-Adresse ab, die einem Hostnamen oder einer IP-Adresse zugeordnet ist.

Hinweis Dieses Element sendet Ablaufverfolgungsinformationen, wenn Sie die Netzwerkablaufverfolgung in Ihrer Anwendung aktivieren. Weitere Informationen finden Sie unter "Netzwerkablaufverfolgung" im .NET Framework.

Der asynchrone BeginGetHostEntry Vorgang muss durch Aufrufen der EndGetHostEntry Methode abgeschlossen werden. In der requestCallback Regel wird die Methode vom Stellvertretung aufgerufen.

Diese Methode blockiert erst, wenn der Vorgang abgeschlossen ist. Um zu blockieren, bis der Vorgang abgeschlossen ist, verwenden Sie die GetHostEntry Methode.

Ausführliche Informationen zur Verwendung des asynchronen Programmiermodells finden Sie unter "Synchrone Methoden asynchron aufrufen".

Gilt für