public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { if (asyncResult != null && !asyncResult.IsCompleted) { throw new InvalidOperationException("Cannot re-call BeginGetRequestStream/BeginGetResponse while a previous call is still in progress"); } CheckIfAborted(); asyncResult = new FtpAsyncResult(callback, state); lock (locker) { if (InFinalState()) { asyncResult.SetCompleted(true, ftpResponse); } else { if (State == RequestState.Before) { State = RequestState.Scheduled; } #if SSHARP ThreadPool.QueueUserWorkItem(ProcessRequest); #else Thread thread = new Thread(ProcessRequest); thread.Start(); #endif } } return(asyncResult); }
private void ProcessRequest() #endif { if (State == RequestState.Scheduled) { ftpResponse = new FtpWebResponse(this, requestUri, method, keepAlive); try { ProcessMethod(); //State = RequestState.Finished; //finalResponse = ftpResponse; asyncResult.SetCompleted(false, ftpResponse); } catch (Exception e) { if (!GetServicePoint().UsesProxy) { State = RequestState.Error; } SetCompleteWithError(e); } } else { if (InProgress()) { FtpStatus status = GetResponseStatus(); ftpResponse.UpdateStatus(status); if (ftpResponse.IsFinal()) { State = RequestState.Finished; } } asyncResult.SetCompleted(false, ftpResponse); } }