Пример #1
0
        /// <summary>
        /// Ends executing an asynchronous request.
        /// </summary>
        private void InternalEndExecuteRequest(IAsyncResult asyncResult)
        {
            AsyncExecutionState state = (AsyncExecutionState)asyncResult.AsyncState;
            AsyncRequestResult  asyncRequestResult = null;
            bool retried = false;

            try
            {
                asyncRequestResult = new AsyncRequestResult(new Response(
                                                                state.CurrentRequest.EndGetResponse(asyncResult)));
            }
            catch (WebException ex)
            {
                // Returns null if the attempt was retried.
                retried = HandleFailedRequest(state, ex, out asyncRequestResult);
            }
            catch (Exception ex) // Unknown exception.
            {
                asyncRequestResult = new AsyncRequestResult(
                    new GoogleApiRequestException(Service, this, null, ex));
            }
            finally
            {
                // If the async result is null, this indicates that the request was retried.
                // Another handler will be executed to respond to that attempt, so do not
                // call the handler yet.
                if (!retried)
                {
                    state.ResponseHandler(asyncRequestResult);
                }
            }
        }