Dns.BeginGetHostEntry Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Asynchroon wordt een hostnaam of IP-adres omgezet in een IPHostEntry exemplaar.
Overloads
| Name | Description |
|---|---|
| BeginGetHostEntry(IPAddress, AsyncCallback, Object) |
Een IP-adres wordt asynchroon omgezet in een IPHostEntry exemplaar. |
| BeginGetHostEntry(String, AsyncCallback, Object) |
Asynchroon wordt een hostnaam of IP-adres omgezet in een IPHostEntry exemplaar. |
BeginGetHostEntry(IPAddress, AsyncCallback, Object)
Een IP-adres wordt asynchroon omgezet in een IPHostEntry exemplaar.
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);
static member BeginGetHostEntry : System.Net.IPAddress * AsyncCallback * obj -> IAsyncResult
Public Shared Function BeginGetHostEntry (address As IPAddress, requestCallback As AsyncCallback, stateObject As Object) As IAsyncResult
Parameters
- address
- IPAddress
Het IP-adres dat moet worden omgezet.
- requestCallback
- AsyncCallback
Een AsyncCallback gemachtigde die verwijst naar de methode die moet worden aangeroepen wanneer de bewerking is voltooid.
- stateObject
- Object
Een door de gebruiker gedefinieerd object dat informatie over de bewerking bevat. Dit object wordt doorgegeven aan de requestCallback gemachtigde wanneer de bewerking is voltooid.
Retouren
Een IAsyncResult exemplaar dat verwijst naar de asynchrone aanvraag.
Uitzonderingen
address is null.
Er is een fout opgetreden bij het oplossen van het probleem address.
address is een ongeldig IP-adres.
Voorbeelden
In het volgende codevoorbeeld wordt de BeginGetHostEntry methode gebruikt om een IP-adres op te lossen naar een IPHostEntry exemplaar.
// 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
Opmerkingen
Met de BeginGetHostEntry methode wordt asynchroon een query uitgevoerd op een DNS-server voor de IP-adressen en aliassen die zijn gekoppeld aan een IP-adres.
Opmerking Dit lid verzendt traceringsgegevens wanneer u netwerktracering inschakelt in uw toepassing. Zie Network Tracing in the .NET Framework voor meer informatie.
De asynchrone BeginGetHostEntry bewerking moet worden voltooid door de EndGetHostEntry methode aan te roepen. Normaal gesproken wordt de methode aangeroepen door de requestCallback gemachtigde.
Deze methode wordt pas geblokkeerd als de bewerking is voltooid. Gebruik de GetHostEntry methode om te blokkeren totdat de bewerking is voltooid.
Zie Synchrone methoden asynchroon aanroepen voor gedetailleerde informatie over het gebruik van het asynchrone programmeermodel
Van toepassing op
BeginGetHostEntry(String, AsyncCallback, Object)
Asynchroon wordt een hostnaam of IP-adres omgezet in een IPHostEntry exemplaar.
public:
static IAsyncResult ^ BeginGetHostEntry(System::String ^ hostNameOrAddress, AsyncCallback ^ requestCallback, System::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
Parameters
- hostNameOrAddress
- String
De hostnaam of het IP-adres dat moet worden omgezet.
- requestCallback
- AsyncCallback
Een AsyncCallback gemachtigde die verwijst naar de methode die moet worden aangeroepen wanneer de bewerking is voltooid.
- stateObject
- Object
Een door de gebruiker gedefinieerd object dat informatie over de bewerking bevat. Dit object wordt doorgegeven aan de requestCallback gemachtigde wanneer de bewerking is voltooid.
Retouren
Een IAsyncResult exemplaar dat verwijst naar de asynchrone aanvraag.
Uitzonderingen
hostNameOrAddress is null.
De lengte van hostNameOrAddress meer dan 255 tekens is.
Er is een fout opgetreden bij het oplossen van het probleem hostNameOrAddress.
hostNameOrAddress is een ongeldig IP-adres.
Voorbeelden
In het volgende codevoorbeeld wordt de BeginGetHostEntry methode gebruikt om een IP-adres op te lossen naar een IPHostEntry exemplaar.
// 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
Opmerkingen
De BeginGetHostEntry methode voert een query uit op een DNS-server voor het IP-adres dat is gekoppeld aan een hostnaam of IP-adres.
Opmerking Dit lid verzendt traceringsgegevens wanneer u netwerktracering inschakelt in uw toepassing. Zie Network Tracing in the .NET Framework voor meer informatie.
De asynchrone BeginGetHostEntry bewerking moet worden voltooid door de EndGetHostEntry methode aan te roepen. Normaal gesproken wordt de methode aangeroepen door de requestCallback gemachtigde.
Deze methode wordt pas geblokkeerd als de bewerking is voltooid. Gebruik de GetHostEntry methode om te blokkeren totdat de bewerking is voltooid.
Zie Synchrone methoden asynchroon aanroepen voor gedetailleerde informatie over het gebruik van het asynchrone programmeermodel.