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 }
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); }
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); }