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(); } } }
public void BeginExecute(Pop3Command command, EndGetResponse callbackFunction) { AsynchronousContext cx = null; Boolean IsResponseMultiLine = false; Boolean IsException = false; if (command is Top || command is Retr || command is List || command is Uidl) { IsResponseMultiLine = true; } try { cx = new AsynchronousPop3ResponseContext(_ResponseEncoding, IsResponseMultiLine, callbackFunction); this.SendCommand(command.GetCommandString()); this._Stream.BeginRead(cx.Buffer.Array, 0, cx.Buffer.Array.Length, this.BeginExecuteCallBack, cx); } catch { IsException = true; throw; } finally { if (IsException == true && cx != null) { cx.Dispose(); } } }
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) { } } }
private void GetResponse(Stream stream, Boolean isMultiLine) { if (this._TcpClient == null) { throw new Pop3ConnectException("Connection to POP3 server is closed"); } using (var cx = new AsynchronousPop3ResponseContext(_ResponseEncoding, isMultiLine)) { _Stream.BeginRead(cx.Buffer.Array, 0, cx.Buffer.Array.Length, this.GetResponseCallback, cx); var bl = _GetResponseDone.WaitOne(_ReceiveTimeout); if (cx.Exception != null) { throw cx.Exception; } if (cx.Timeout == true || bl == false) { throw new Pop3ReceiveException("Response timeout"); } this.ReadText(stream, isMultiLine, cx.Data.ToArray()); } this._Commnicating = false; }