Dns.BeginResolve(String, AsyncCallback, Object) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
注意事項
BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202
注意事項
BeginResolve has been deprecated. Use BeginGetHostEntry instead.
注意事項
BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202
非同期要求を開始して DNS ホスト名または IP アドレスを IPAddress インスタンスに解決します。
public:
static IAsyncResult ^ BeginResolve(System::String ^ hostName, AsyncCallback ^ requestCallback, System::Object ^ stateObject);
[System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static IAsyncResult BeginResolve (string hostName, AsyncCallback? requestCallback, object? stateObject);
[System.Obsolete("BeginResolve has been deprecated. Use BeginGetHostEntry instead.")]
public static IAsyncResult BeginResolve (string hostName, AsyncCallback? requestCallback, object? stateObject);
[System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static IAsyncResult BeginResolve (string hostName, AsyncCallback requestCallback, object stateObject);
[System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")]
public static IAsyncResult BeginResolve (string hostName, AsyncCallback requestCallback, object stateObject);
public static IAsyncResult BeginResolve (string hostName, AsyncCallback requestCallback, object stateObject);
[<System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. https://go.microsoft.com/fwlink/?linkid=14202")>]
static member BeginResolve : string * AsyncCallback * obj -> IAsyncResult
[<System.Obsolete("BeginResolve has been deprecated. Use BeginGetHostEntry instead.")>]
static member BeginResolve : string * AsyncCallback * obj -> IAsyncResult
[<System.Obsolete("BeginResolve is obsoleted for this type, please use BeginGetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member BeginResolve : string * AsyncCallback * obj -> IAsyncResult
static member BeginResolve : string * AsyncCallback * obj -> IAsyncResult
Public Shared Function BeginResolve (hostName As String, requestCallback As AsyncCallback, stateObject As Object) As IAsyncResult
パラメーター
- hostName
- String
ホストの DNS 名。
- requestCallback
- AsyncCallback
操作の完了時に呼び出すメソッドを参照する AsyncCallback デリゲート。
- stateObject
- Object
操作に関する情報を格納するユーザー定義のオブジェクト。 このオブジェクトは、操作の完了時に requestCallback
デリゲートに渡されます。
戻り値
非同期要求を参照する IAsyncResult インスタンス。
- 属性
例外
hostName
が null
です。
呼び出し元に、DNS 情報にアクセスするためのアクセス許可がありません。
例
次の例では、 を使用 BeginResolve して DNS ホスト名を に IPAddress解決します。
public ref class DnsBeginGetHostByName
{
public:
static System::Threading::ManualResetEvent^ allDone = nullptr;
ref class RequestState
{
public:
IPHostEntry^ host;
RequestState()
{
host = nullptr;
}
};
static void RespCallback( IAsyncResult^ ar )
{
try
{
// Convert the IAsyncResult* Object* to a RequestState Object*.
RequestState^ tempRequestState = dynamic_cast<RequestState^>(ar->AsyncState);
// End the asynchronous request.
tempRequestState->host = Dns::EndResolve( ar );
allDone->Set();
}
catch ( ArgumentNullException^ e )
{
Console::WriteLine( "ArgumentNullException caught!!!" );
Console::WriteLine( "Source : {0}", e->Source );
Console::WriteLine( "Message : {0}", e->Message );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception caught!!!" );
Console::WriteLine( "Source : {0}", e->Source );
Console::WriteLine( "Message : {0}", e->Message );
}
}
};
int main()
{
DnsBeginGetHostByName::allDone = gcnew ManualResetEvent( false );
// Create an instance of the RequestState class.
DnsBeginGetHostByName::RequestState^ myRequestState =
gcnew DnsBeginGetHostByName::RequestState;
// Begin an asynchronous request for information like host name, IP addresses, or
// aliases for specified the specified URI.
IAsyncResult^ asyncResult = Dns::BeginResolve( "www.contoso.com",
gcnew AsyncCallback( DnsBeginGetHostByName::RespCallback ), myRequestState );
// Wait until asynchronous call completes.
DnsBeginGetHostByName::allDone->WaitOne();
Console::WriteLine( "Host name : {0}", myRequestState->host->HostName );
Console::WriteLine( "\nIP address list : " );
for ( int index = 0; index < myRequestState->host->AddressList->Length; index++ )
Console::WriteLine( myRequestState->host->AddressList[ index ] );
Console::WriteLine( "\nAliases : " );
for ( int index = 0; index < myRequestState->host->Aliases->Length; index++ )
Console::WriteLine( myRequestState->host->Aliases[ index ] );
}
class DnsBeginGetHostByName
{
public static System.Threading.ManualResetEvent allDone = null;
class RequestState
{
public IPHostEntry host;
public RequestState()
{
host = null;
}
}
public static void Main()
{
allDone = new ManualResetEvent(false);
// Create an instance of the RequestState class.
RequestState myRequestState = new RequestState();
// Begin an asynchronous request for information like host name, IP addresses, or
// aliases for specified the specified URI.
IAsyncResult asyncResult = Dns.BeginResolve("www.contoso.com", new AsyncCallback(RespCallback), myRequestState );
// Wait until asynchronous call completes.
allDone.WaitOne();
Console.WriteLine("Host name : " + myRequestState.host.HostName);
Console.WriteLine("\nIP address list : ");
for(int index=0; index < myRequestState.host.AddressList.Length; index++)
{
Console.WriteLine(myRequestState.host.AddressList[index]);
}
Console.WriteLine("\nAliases : ");
for(int index=0; index < myRequestState.host.Aliases.Length; index++)
{
Console.WriteLine(myRequestState.host.Aliases[index]);
}
}
private static void RespCallback(IAsyncResult ar)
{
try
{
// Convert the IAsyncResult object to a RequestState object.
RequestState tempRequestState = (RequestState)ar.AsyncState;
// End the asynchronous request.
tempRequestState.host = Dns.EndResolve(ar);
allDone.Set();
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
}
}
Class DnsBeginGetHostByName
Class RequestState
Public host As IPHostEntry
Public Sub New()
host = Nothing
End Sub
End Class
Public Shared Sub Main()
Try
' Create an instance of the RequestState class.
Dim myRequestState As New RequestState()
' Begin an asynchronous request for information such as the host name, IP addresses,
' or aliases for the specified URI.
Dim asyncResult As IAsyncResult = CType(Dns.BeginResolve("www.contoso.com", AddressOf RespCallback, myRequestState),IAsyncResult)
' Wait until asynchronous call completes.
While asyncResult.IsCompleted <> True
End While
Console.WriteLine(("Host name : " + myRequestState.host.HostName))
Console.WriteLine(ControlChars.Cr + "IP address list : ")
Dim index As Integer
For index = 0 To myRequestState.host.AddressList.Length - 1
Console.WriteLine(myRequestState.host.AddressList(index))
Next index
Console.WriteLine(ControlChars.Cr + "Aliases : ")
For index = 0 To myRequestState.host.Aliases.Length - 1
Console.WriteLine(myRequestState.host.Aliases(index))
Next index
catch e as Exception
Console.WriteLine("Exception caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
End Try
End Sub
Private Shared Sub RespCallback(ar As IAsyncResult)
Try
' Convert the IAsyncResult object to a RequestState object.
Dim tempRequestState As RequestState = CType(ar.AsyncState, RequestState)
' End the asynchronous request.
tempRequestState.host = Dns.EndResolve(ar)
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
Catch e As Exception
Console.WriteLine("Exception caught!!!")
Console.WriteLine(("Source : " + e.Source))
Console.WriteLine(("Message : " + e.Message))
End Try
End Sub
注釈
非同期 BeginResolve 操作は、 メソッドを呼び出して完了する EndResolve 必要があります。 通常、 メソッドはデリゲートによって requestCallback
呼び出されます。
このメソッドは、操作が完了するまでブロックしません。 操作が完了するまでブロックするには、 メソッドを使用します Resolve 。
非同期プログラミング モデルの使用の詳細については、「 同期メソッドの非同期呼び出し」を参照してください。
注意
このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「 .NET Framework のネットワーク トレース」を参照してください。
適用対象
こちらもご覧ください
.NET