Пример #1
0
 /// <summary>Asynchronously resolves a host name or IP address to an <see cref="T:System.Net.IPHostEntry" /> instance.</summary>
 /// <returns>An <see cref="T:System.IAsyncResult" /> instance that references the asynchronous request.</returns>
 /// <param name="hostNameOrAddress">The host name or IP address to resolve.</param>
 /// <param name="requestCallback">An <see cref="T:System.AsyncCallback" /> delegate that references the method to invoke when the operation is complete. </param>
 /// <param name="stateObject">A user-defined object that contains information about the operation. This object is passed to the <paramref name="requestCallback" /> delegate when the operation is complete.</param>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="hostNameOrAddress" /> is null. </exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException">The length of <paramref name="hostNameOrAddress" /> is greater than 126 characters. </exception>
 /// <exception cref="T:System.Net.Sockets.SocketException">An error is encountered when resolving <paramref name="hostNameOrAddress" />. </exception>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="hostNameOrAddress" /> is an invalid IP address.</exception>
 public static IAsyncResult BeginGetHostEntry(string hostNameOrAddress, AsyncCallback requestCallback, object stateObject)
 {
     if (hostNameOrAddress == null)
     {
         throw new ArgumentNullException("hostName");
     }
     if (hostNameOrAddress == "0.0.0.0" || hostNameOrAddress == "::0")
     {
         throw new ArgumentException("Addresses 0.0.0.0 (IPv4) and ::0 (IPv6) are unspecified addresses. You cannot use them as target address.", "hostNameOrAddress");
     }
     Dns.GetHostEntryNameCallback getHostEntryNameCallback = new Dns.GetHostEntryNameCallback(Dns.GetHostEntry);
     return(getHostEntryNameCallback.BeginInvoke(hostNameOrAddress, requestCallback, stateObject));
 }
Пример #2
0
        /// <summary>Ends an asynchronous request for DNS information.</summary>
        /// <returns>An <see cref="T:System.Net.IPHostEntry" /> instance that contains address information about the host.</returns>
        /// <param name="asyncResult">An <see cref="T:System.IAsyncResult" /> instance returned by a call to an <see cref="Overload:System.Net.Dns.BeginGetHostEntry" /> method.</param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="asyncResult" /> is null. </exception>
        public static IPHostEntry EndGetHostEntry(IAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            AsyncResult asyncResult2 = (AsyncResult)asyncResult;

            if (asyncResult2.AsyncDelegate is Dns.GetHostEntryIPCallback)
            {
                return(((Dns.GetHostEntryIPCallback)asyncResult2.AsyncDelegate).EndInvoke(asyncResult));
            }
            Dns.GetHostEntryNameCallback getHostEntryNameCallback = (Dns.GetHostEntryNameCallback)asyncResult2.AsyncDelegate;
            return(getHostEntryNameCallback.EndInvoke(asyncResult));
        }