當前位置: 首頁>>代碼示例>>C#>>正文


C# Dns.EndResolve方法代碼示例

本文整理匯總了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;未經允許,請勿轉載。