本文整理汇总了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);
}
}
}
开发者ID:.NET开发者,项目名称:System.Net,代码行数:62,代码来源:Dns.EndResolve
示例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);
}
}
开发者ID:C#程序员,项目名称:System.Net,代码行数:42,代码来源:Dns.EndResolve
注:本文中的System.Net.Dns.EndResolve方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论