示例#1
0
        private void BeginExecuteCallBack(IAsyncResult result)
        {
            AsynchronousPop3ResponseContext cx = (AsynchronousPop3ResponseContext)result.AsyncState;
            Boolean IsException = false;

            try
            {
                Int32 size = this._Stream.EndRead(result);
                if (cx.ReadBuffer(size) == true)
                {
                    this._Stream.BeginRead(cx.Buffer.Array, 0, cx.Buffer.Array.Length, this.BeginExecuteCallBack, cx);
                }
                else
                {
                    cx.OnEndGetResponse();
                    cx.Dispose();
                }
            }
            catch
            {
                IsException = true;
                throw;
            }
            finally
            {
                if (IsException == true && cx != null)
                {
                    cx.Dispose();
                }
            }
        }
示例#2
0
        private void GetResponseCallback(IAsyncResult result)
        {
            AsynchronousPop3ResponseContext cx = null;

            try
            {
                cx = (AsynchronousPop3ResponseContext)result.AsyncState;
                if (this._TcpClient == null)
                {
                    throw new Pop3ConnectException("Connection to POP3 server is closed");
                }
                Int32    size = _Stream.EndRead(result);
                TimeSpan ts   = DateTime.Now - cx.StartTime;

                if (ts.TotalMilliseconds > this._ReceiveTimeout)
                {
                    cx.Timeout = true;
                    _GetResponseDone.Set();
                }
                if (cx.ReadBuffer(size) == true)
                {
                    _Stream.BeginRead(cx.Buffer.Array, 0, cx.Buffer.Array.Length, this.GetResponseCallback, cx);
                }
                else
                {
                    _GetResponseDone.Set();
                }
            }
            catch (Exception ex)
            {
                cx.Exception = ex;
            }
            if (cx.Exception != null)
            {
                try
                {
                    _GetResponseDone.Set();
                }
                catch (ObjectDisposedException) { }
            }
        }