Пример #1
0
        /// <summary>
        /// Begins an asynchronous operation to send the specified
        /// <see cref="AK.Net.Dns.DnsQuery"/> to the specified end point
        /// and return the <see cref="AK.Net.Dns.DnsReply"/>.
        /// </summary>
        /// <param name="query">The query to send.</param>
        /// <param name="endpoint">The transport end point.</param>
        /// <param name="callback">The method to invoke once the asynchronous operation
        /// has completed.</param>
        /// <param name="state">The user-defined state object to associate with the
        /// asynchronous operation.</param>
        /// <returns>The asynchronous operation result.</returns>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when <paramref name="query"/>, <paramref name="endpoint"/> or
        /// <paramref name="callback"/> is <see langword="null"/>.
        /// </exception>
        public virtual IAsyncResult BeginSend(DnsQuery query, IPEndPoint endpoint,
                                              AsyncCallback callback, object state)
        {
            Guard.NotNull(endpoint, "endpoint");
            Guard.NotNull(callback, "callback");

            SendAsyncState asyncState = new SendAsyncState(callback, state);

            asyncState.QueueOperation(delegate {
                try {
                    asyncState.Result = Send(query, endpoint);
                } catch (DnsTransportException exc) {
                    asyncState.Exception = exc;
                } finally {
                    asyncState.OnComplete();
                }
            });

            return(asyncState);
        }