Dns.BeginGetHostEntry メソッド

定義

ホスト名または IP アドレスを IPHostEntry インスタンスに非同期的に解決します。

オーバーロード

名前 説明
BeginGetHostEntry(IPAddress, AsyncCallback, Object)

IP アドレスを IPHostEntry インスタンスに非同期的に解決します。

BeginGetHostEntry(String, AsyncCallback, Object)

ホスト名または IP アドレスを IPHostEntry インスタンスに非同期的に解決します。

BeginGetHostEntry(IPAddress, AsyncCallback, Object)

ソース:
Dns.cs
ソース:
Dns.cs
ソース:
Dns.cs
ソース:
Dns.cs
ソース:
Dns.cs

IP アドレスを IPHostEntry インスタンスに非同期的に解決します。

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

パラメーター

address
IPAddress

解決する IP アドレス。

requestCallback
AsyncCallback

操作が完了したときに呼び出すメソッドを参照する AsyncCallback デリゲート。

stateObject
Object

操作に関する情報を含むユーザー定義オブジェクト。 このオブジェクトは、操作が完了すると、 requestCallback デリゲートに渡されます。

返品

非同期要求を参照する IAsyncResult インスタンス。

例外

addressnullです。

addressを解決するときにエラーが発生しました。

address が無効な IP アドレスです。

次のコード例では、 BeginGetHostEntry メソッドを使用して IP アドレスを IPHostEntry インスタンスに解決します。

// 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

注釈

BeginGetHostEntryメソッドは、DNS サーバーに対して、IP アドレスに関連付けられている IP アドレスとエイリアスを非同期的に照会します。

メモ このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「.NET Framework の Network Tracingを参照してください。

非同期 BeginGetHostEntry 操作は、 EndGetHostEntry メソッドを呼び出すことによって完了する必要があります。 通常、メソッドは requestCallback デリゲートによって呼び出されます。

このメソッドは、操作が完了するまでブロックしません。 操作が完了するまでブロックするには、 GetHostEntry メソッドを使用します。

非同期プログラミング モデルの使用の詳細については、「非同期メソッドの呼び出し」を参照してください。

適用対象

BeginGetHostEntry(String, AsyncCallback, Object)

ソース:
Dns.cs
ソース:
Dns.cs
ソース:
Dns.cs
ソース:
Dns.cs
ソース:
Dns.cs

ホスト名または IP アドレスを IPHostEntry インスタンスに非同期的に解決します。

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

パラメーター

hostNameOrAddress
String

解決するホスト名または IP アドレス。

requestCallback
AsyncCallback

操作が完了したときに呼び出すメソッドを参照する AsyncCallback デリゲート。

stateObject
Object

操作に関する情報を含むユーザー定義オブジェクト。 このオブジェクトは、操作が完了すると、 requestCallback デリゲートに渡されます。

返品

非同期要求を参照する IAsyncResult インスタンス。

例外

hostNameOrAddressnullです。

hostNameOrAddressの長さが 255 文字を超えています。

hostNameOrAddressを解決するときにエラーが発生しました。

hostNameOrAddress が無効な IP アドレスです。

次のコード例では、 BeginGetHostEntry メソッドを使用して IP アドレスを IPHostEntry インスタンスに解決します。

// 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

注釈

BeginGetHostEntry メソッドは、ホスト名または IP アドレスに関連付けられている IP アドレスを DNS サーバーに照会します。

メモ このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「.NET Framework の Network Tracingを参照してください。

非同期 BeginGetHostEntry 操作は、 EndGetHostEntry メソッドを呼び出すことによって完了する必要があります。 通常、メソッドは requestCallback デリゲートによって呼び出されます。

このメソッドは、操作が完了するまでブロックしません。 操作が完了するまでブロックするには、 GetHostEntry メソッドを使用します。

非同期プログラミング モデルの使用の詳細については、「非同期メソッドの 呼び出し」を参照してください。

適用対象