Dns.BeginGetHostEntry Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Resuelve de forma asincrónica un nombre de host o una dirección IP en una IPHostEntry instancia de .
Sobrecargas
| Nombre | Description |
|---|---|
| BeginGetHostEntry(IPAddress, AsyncCallback, Object) |
Resuelve de forma asincrónica una dirección IP en una IPHostEntry instancia. |
| BeginGetHostEntry(String, AsyncCallback, Object) |
Resuelve de forma asincrónica un nombre de host o una dirección IP en una IPHostEntry instancia de . |
BeginGetHostEntry(IPAddress, AsyncCallback, Object)
- Source:
- Dns.cs
- Source:
- Dns.cs
- Source:
- Dns.cs
- Source:
- Dns.cs
- Source:
- Dns.cs
Resuelve de forma asincrónica una dirección IP en una IPHostEntry instancia.
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
Parámetros
- address
- IPAddress
Dirección IP que se va a resolver.
- requestCallback
- AsyncCallback
AsyncCallback Delegado que hace referencia al método que se va a invocar cuando se completa la operación.
- stateObject
- Object
Objeto definido por el usuario que contiene información sobre la operación. Este objeto se pasa al requestCallback delegado cuando se completa la operación.
Devoluciones
Instancia IAsyncResult de que hace referencia a la solicitud asincrónica.
Excepciones
address es null.
Se produce un error al resolver address.
address es una dirección IP no válida.
Ejemplos
En el ejemplo de código siguiente se usa el BeginGetHostEntry método para resolver una dirección IP en una IPHostEntry instancia.
// 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
Comentarios
El BeginGetHostEntry método consulta de forma asincrónica un servidor DNS para las direcciones IP y los alias asociados a una dirección IP.
Nota Este miembro emite información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, vea Network Tracing in the .NET Framework.
La operación asincrónica BeginGetHostEntry debe completarse llamando al EndGetHostEntry método . Normalmente, el delegado invoca el requestCallback método .
Este método no se bloquea hasta que se complete la operación. Para bloquear hasta que se complete la operación, use el GetHostEntry método .
Para obtener información detallada sobre el uso del modelo de programación asincrónica, vea Llamar a métodos sincrónicos de forma asincrónica.
Se aplica a
BeginGetHostEntry(String, AsyncCallback, Object)
- Source:
- Dns.cs
- Source:
- Dns.cs
- Source:
- Dns.cs
- Source:
- Dns.cs
- Source:
- Dns.cs
Resuelve de forma asincrónica un nombre de host o una dirección IP en una IPHostEntry instancia de .
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
Parámetros
- hostNameOrAddress
- String
Nombre de host o dirección IP que se va a resolver.
- requestCallback
- AsyncCallback
AsyncCallback Delegado que hace referencia al método que se va a invocar cuando se completa la operación.
- stateObject
- Object
Objeto definido por el usuario que contiene información sobre la operación. Este objeto se pasa al requestCallback delegado cuando se completa la operación.
Devoluciones
Instancia IAsyncResult de que hace referencia a la solicitud asincrónica.
Excepciones
hostNameOrAddress es null.
La longitud de es mayor que hostNameOrAddress 255 caracteres.
Se produce un error al resolver hostNameOrAddress.
hostNameOrAddress es una dirección IP no válida.
Ejemplos
En el ejemplo de código siguiente se usa el BeginGetHostEntry método para resolver una dirección IP en una IPHostEntry instancia.
// 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
Comentarios
El BeginGetHostEntry método consulta un servidor DNS para la dirección IP asociada a un nombre de host o una dirección IP.
Nota Este miembro emite información de seguimiento al habilitar el seguimiento de red en la aplicación. Para obtener más información, vea Network Tracing in the .NET Framework.
La operación asincrónica BeginGetHostEntry debe completarse llamando al EndGetHostEntry método . Normalmente, el delegado invoca el requestCallback método .
Este método no se bloquea hasta que se complete la operación. Para bloquear hasta que se complete la operación, use el GetHostEntry método .
Para obtener información detallada sobre el uso del modelo de programación asincrónica, vea Llamar a métodos sincrónicos de forma asincrónica.