Beispiel #1
0
        private void SendCommandCallback(IAsyncResult result)
        {
            AsynchronousSendContext cx = null;

            try
            {
                cx = (AsynchronousSendContext)result.AsyncState;
                _Stream.EndWrite(result);
                if (cx.IsSendAllBytes == true)
                {
                    cx.FillBuffer();
                    _Stream.BeginWrite(cx.Buffer.Array, 0, cx.SendBufferSize, this.SendCommandCallback, cx);
                }
                else
                {
                    _SendCommandDone.Set();
                }
            }
            catch (Exception ex)
            {
                cx.Exception = ex;
            }
            if (cx.Exception != null)
            {
                try
                {
                    _SendCommandDone.Set();
                }
                catch (ObjectDisposedException) { }
            }
        }
Beispiel #2
0
        private void SendCommand(Byte[] bytes)
        {
            AsynchronousSendContext cx = null;

            if (this._TcpClient == null)
            {
                throw new Pop3ConnectException("Pop3 connection is closed");
            }
            try
            {
                cx = new AsynchronousSendContext(Encoding.ASCII, bytes);
                cx.FillBuffer();
                _Stream.BeginWrite(cx.Buffer.Array, 0, cx.SendBufferSize, this.SendCommandCallback, cx);
                _SendCommandDone.WaitOne();
            }
            catch (Exception ex)
            {
                throw new Pop3SendException(ex);
            }
            finally
            {
                if (cx != null)
                {
                    cx.Dispose();
                }
            }

            if (cx.Exception != null)
            {
                throw cx.Exception;
            }
        }