本文整理匯總了C#中System.Net.Dns.EndResolve方法的典型用法代碼示例。如果您正苦於以下問題:C# Dns.EndResolve方法的具體用法?C# Dns.EndResolve怎麽用?C# Dns.EndResolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了Dns.EndResolve方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RequestState
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);
}
}
}
示例2: Dns.EndResolve(IAsyncResult ar)
//引入命名空間
using System;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;
class MainClass
{
private static void Resolved(IAsyncResult ar)
{
string buffer;
IPHostEntry iphe = Dns.EndResolve(ar);
buffer = "Host name: " + iphe.HostName;
Console.WriteLine(buffer);
foreach(string alias in iphe.Aliases)
{
buffer = "Alias: " + alias;
Console.WriteLine(buffer);
}
foreach(IPAddress addrs in iphe.AddressList)
{
buffer = "Address: " + addrs.ToString();
Console.WriteLine(buffer);
}
}
public static void Main()
{
AsyncCallback OnResolved;
OnResolved = new AsyncCallback(Resolved);
string addr = "www.java2s.com";
Object state = new Object();
Dns.BeginResolve(addr, OnResolved, state);
}
}