private void GetHostEntryCallBack(IAsyncResult ar)
        {
            GetHostEntryState state = ar.AsyncState as GetHostEntryState;

            if (state != null)
            {
                try
                {
                    state.resolvedIPs = Dns.EndGetHostEntry(ar);
                    state.resetEvent.Set();
                }
                catch (SocketException sex)
                {
                    state.exception = sex;
                    state.resetEvent.Set();
                }
            }
            else
            {
                state.exception = new SocketException((int)SocketError.HostNotFound);
                state.resetEvent.Set();
            }
        }
        private IPHostEntry GetHostEntry()
        {
            GetHostEntryState state     = new GetHostEntryState();
            IPHostEntry       hostEntry = null;

            try
            {
                Dns.BeginGetHostEntry(Host, getHostEntryCallBack, state);
                if (!state.resetEvent.WaitOne(2000, false))
                {
                    state.resetEvent.Reset();
                    throw new SocketException((int)SocketError.HostNotFound);
                }
                else
                {
                    if (state.exception != null)
                    {
                        //done this way because the CallBack is on another thread,
                        //so any exceptions it throws will not be caught by calling code
                        throw state.exception;
                    }
                    else
                    {
                        state.resetEvent.Reset();
                    }
                    hostEntry = state.resolvedIPs;
                }
            }
            catch (Exception ex)
            {
                if (RelayNodeMapping.log.IsErrorEnabled)
                {
                    RelayNodeMapping.log.ErrorFormat("Error getting IP address for host '{0}': {1}", Host, ex.Message);
                }
            }
            return(hostEntry);
        }