示例#1
0
        /// <summary>
        /// Begins executing this async request.
        /// </summary>
        /// <param name="callback">The AsyncCallback delegate.</param>
        /// <param name="state">An object that contains state information for this request.</param>
        /// <returns>An IAsyncResult that references the asynchronous request.</returns>
        internal IAsyncResult BeginExecute(AsyncCallback callback, object state)
        {
            this.Validate();

            IEwsHttpWebRequest request = this.BuildEwsHttpWebRequest();

            WebAsyncCallStateAnchor wrappedState = new WebAsyncCallStateAnchor(this, request, callback /* user callback */, state /* user state */);

            // BeginGetResponse() does not throw interesting exceptions
            IAsyncResult webAsyncResult = request.BeginGetResponse(SimpleServiceRequestBase.WebRequestAsyncCallback, wrappedState);

            return(new AsyncRequestResult(this, request, webAsyncResult, state /* user state */));
        }
示例#2
0
        /// <summary>
        /// Async callback method for HttpWebRequest async requests.
        /// </summary>
        /// <param name="webAsyncResult">An IAsyncResult that references the asynchronous request.</param>
        private static void WebRequestAsyncCallback(IAsyncResult webAsyncResult)
        {
            WebAsyncCallStateAnchor wrappedState = webAsyncResult.AsyncState as WebAsyncCallStateAnchor;

            if (wrappedState != null && wrappedState.AsyncCallback != null)
            {
                AsyncRequestResult asyncRequestResult = new AsyncRequestResult(
                    wrappedState.ServiceRequest,
                    wrappedState.WebRequest,
                    webAsyncResult, /* web async result */
                    wrappedState.AsyncState /* user state */);

                // Call user's call back
                wrappedState.AsyncCallback(asyncRequestResult);
            }
        }