示例#1
0
        private void SetTimeout(IAsyncResult asyncResult, TimeOutState timeOutState)
        {
#if FRAMEWORK && !PocketPC && !WIN8_1
            if (Timeout != 0)
            {
                ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), timeOutState, Timeout, true);
            }
#endif
        }
示例#2
0
        private void WriteRequestBodyAsync(HttpWebRequest webRequest, Action <HttpResponse> callback)
        {
            IAsyncResult asyncResult;

            _timeoutState = new TimeOutState {
                Request = webRequest
            };

            if (Method == "GET")
            {
                // GET请求直接获取response
                asyncResult = webRequest.BeginGetResponse(r => ResponseCallback(r, callback), webRequest);
            }
            else
            {
#if !WINDOWS_PHONE && !PocketPC && !WIN8_1
                webRequest.ContentLength = CalculateContentLength();
#endif

                asyncResult = webRequest.BeginGetRequestStream(result => RequestStreamCallback(result, callback), webRequest);
            }

            SetTimeout(asyncResult, _timeoutState);
        }
示例#3
0
        private void SetTimeout(IAsyncResult asyncResult, TimeOutState timeOutState)
        {
#if FRAMEWORK && !PocketPC && !WIN8_1
            if (Timeout != 0)
            {
                ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), timeOutState, Timeout, true);
            }
#endif
        }
示例#4
0
        private void WriteRequestBodyAsync(HttpWebRequest webRequest, Action<HttpResponse> callback)
        {
            IAsyncResult asyncResult;
            _timeoutState = new TimeOutState { Request = webRequest };

            if (Method == "GET")
            {
                // GET请求直接获取response
                asyncResult = webRequest.BeginGetResponse(r => ResponseCallback(r, callback), webRequest);
            }
            else
            {

#if !WINDOWS_PHONE && !PocketPC && !WIN8_1
                webRequest.ContentLength = CalculateContentLength();
#endif

                asyncResult = webRequest.BeginGetRequestStream(result => RequestStreamCallback(result, callback), webRequest);
            }

            SetTimeout(asyncResult, _timeoutState);
        }