コード例 #1
0
        /// <summary>
        /// Completes the execution of an asynchronous query operation.
        /// </summary>
        /// <param name="ar">The async result returned by <see cref="BeginQuery" />.</param>
        /// <returns>The query response message.</returns>
        /// <remarks>
        /// <note>
        /// Each call to <see cref="BeginQuery" /> must be matched with
        /// a call to EndQuery.
        /// </note>
        /// </remarks>
        public Msg EndQuery(IAsyncResult ar)
        {
            var arQuery = (AsyncResult)ar;

            arQuery.Wait();

            try
            {
                if (arQuery.Exception != null)
                {
                    throw arQuery.Exception;
                }
#if TRACE
                if (error != null)
                {
                    query._Trace(base.Router, 2, "Q/R Finish", null, "Exception: {0}", error.ToString());
                }
                else
                {
                    var sb = new StringBuilder(512);

                    sb.Append("\r\nResponse:\r\n\r\n");
                    response._TraceDetails(base.Router, sb);

                    query._Trace(base.Router, 2, "Q/R Finish", "", sb.ToString());
                }
#endif
                Assertion.Test(error != null || response != null, "Either an error or a response should be present.");

                if (error != null)
                {
                    Helper.Rethrow(error);
                    throw null;
                }
                else
                {
                    return(response);
                }
            }
            finally
            {
                arQuery.Dispose();
            }
        }