Dns.BeginGetHostEntry Methode

Definition

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

Überlädt

Name Beschreibung
BeginGetHostEntry(IPAddress, AsyncCallback, Object)

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

BeginGetHostEntry(String, AsyncCallback, Object)

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

BeginGetHostEntry(IPAddress, AsyncCallback, Object)

Quelle:
Dns.cs
Quelle:
Dns.cs
Quelle:
Dns.cs
Quelle:
Dns.cs
Quelle:
Dns.cs

Löst asynchron eine IP-Adresse 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 ip-Adresse, die aufgelöst werden soll.

requestCallback
AsyncCallback

Ein AsyncCallback Delegat, der auf die Methode verweist, die aufgerufen werden soll, wenn der Vorgang abgeschlossen ist.

stateObject
Object

Ein benutzerdefiniertes Objekt, das Informationen zum Vorgang enthält. Dieses Objekt wird an die requestCallback Stellvertretung übergeben, wenn der Vorgang abgeschlossen ist.

Gibt zurück

Eine IAsyncResult Instanz, die auf die asynchrone Anforderung verweist.

Ausnahmen

address ist null.

Beim Auflösen addressist ein Fehler aufgetreten.

address ist eine ungültige IP-Adresse.

Beispiele

Im folgenden Codebeispiel wird die BeginGetHostEntry Methode verwendet, um eine IP-Adresse in eine IPHostEntry Instanz aufzulösen.

// 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 fragt asynchron einen DNS-Server nach den IP-Adressen und Aliasen ab, die einer IP-Adresse zugeordnet sind.

Hinweis Dieses Mitglied gibt Ablaufverfolgungsinformationen aus, wenn Sie die Netzwerkablaufverfolgung in Ihrer Anwendung aktivieren. Weitere Informationen finden Sie unter Network-Ablaufverfolgung im .NET Framework.

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

Diese Methode wird erst blockiert, 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 asynchrones Aufrufen synchroner Methoden

Gilt für:

BeginGetHostEntry(String, AsyncCallback, Object)

Quelle:
Dns.cs
Quelle:
Dns.cs
Quelle:
Dns.cs
Quelle:
Dns.cs
Quelle:
Dns.cs

Löst asynchron einen Hostnamen oder eine IP-Adresse 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 Hostname oder die IP-Adresse, die aufgelöst werden soll.

requestCallback
AsyncCallback

Ein AsyncCallback Delegat, der auf die Methode verweist, die aufgerufen werden soll, wenn der Vorgang abgeschlossen ist.

stateObject
Object

Ein benutzerdefiniertes Objekt, das Informationen zum Vorgang enthält. Dieses Objekt wird an die requestCallback Stellvertretung übergeben, wenn der Vorgang abgeschlossen ist.

Gibt zurück

Eine IAsyncResult Instanz, die auf die asynchrone Anforderung verweist.

Ausnahmen

hostNameOrAddress ist null.

Die Länge beträgt hostNameOrAddress mehr als 255 Zeichen.

Beim Auflösen hostNameOrAddressist ein Fehler aufgetreten.

hostNameOrAddress ist eine ungültige IP-Adresse.

Beispiele

Im folgenden Codebeispiel wird die BeginGetHostEntry Methode verwendet, um eine IP-Adresse in eine IPHostEntry Instanz aufzulösen.

// 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 fragt einen DNS-Server für die IP-Adresse ab, die einem Hostnamen oder einer IP-Adresse zugeordnet ist.

Hinweis Dieses Mitglied gibt Ablaufverfolgungsinformationen aus, wenn Sie die Netzwerkablaufverfolgung in Ihrer Anwendung aktivieren. Weitere Informationen finden Sie unter Network-Ablaufverfolgung im .NET Framework.

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

Diese Methode wird erst blockiert, 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 asynchrones Aufrufen synchroner Methoden.

Gilt für: