private void DoGetResponse(object obj) { HttpWebRequestState internalState = (HttpWebRequestState)obj; HttpWebResponse response = null; try { response = (HttpWebResponse)internalState.Request.GetResponse(); } catch { // this catches time-outs and other stuff like that } if (internalState.Callback != null) { internalState.Callback(internalState.Request, response, internalState.State); } this.busy = false; }
public void GetResponseAsync(AsyncResponseCallback callback, object state) { if (!this.busy) { this.busy = true; HttpWebRequestState internalState = new HttpWebRequestState(this.request, callback, state); ThreadPool.QueueUserWorkItem(DoGetResponse, internalState); } }