示例#1
0
        void ProcessRequest()
        {
            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) {
                    State = RequestState.Error;
                    SetCompleteWithError(e);
                }
            }
            else
            {
                if (InProgress())
                {
                    FtpStatus status = GetResponseStatus();

                    ftpResponse.UpdateStatus(status);

                    if (ftpResponse.IsFinal())
                    {
                        State = RequestState.Finished;
                    }
                }

                asyncResult.SetCompleted(false, ftpResponse);
            }
        }
示例#2
0
        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;
                    }

                    Thread thread = new Thread(ProcessRequest);
                    thread.Start();
                }
            }

            return(asyncResult);
        }
示例#3
0
		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;

					Thread thread = new Thread (ProcessRequest);
					thread.Start ();
				}
			}

			return asyncResult;
		}