/// 非同期でPOP3メールサーバーからのデータを受信します。 /// 受信データがまだある場合、再度BeginExecuteメソッドを呼び出し残りのデータを取得します。 /// <summary> /// Send a command with asynchronous and get response text by first parameter of callbackFunction. /// If there is more data to receive,continously call BeginExecuteCallback method and get response data. /// 非同期でPOP3メールサーバーからのデータを受信します。 /// 受信データがまだある場合、再度BeginExecuteメソッドを呼び出し残りのデータを取得します。 /// </summary> /// <param name="result"></param> private void BeginSendCallBack(IAsyncResult result) { DataReceiveContext cx = (DataReceiveContext)result.AsyncState; Boolean IsException = false; try { Int32 size = this.Stream.EndRead(result); if (cx.ReadBuffer(size) == true) { //まだデータが受信中の場合、再度レスポンスデータを受信します。 var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.BeginSendCallBack, cx); } else { cx.OnEndGetResponse(); cx.Dispose(); } } catch (Exception ex) { IsException = true; this.OnError(ex); } finally { if (IsException == true && cx != null) { cx.Dispose(); } } }
private void ExecuteIdleCallback(IAsyncResult result) { DataReceiveContext cx = null; try { cx = (DataReceiveContext)result.AsyncState; if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } Int32 size = Stream.EndRead(result); if (cx.ReadBuffer(size) == true) { var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); } else { cx.Dispose(); } } catch (Exception ex) { cx.Exception = ex; this.OnError(ex); } finally { if (cx.Exception != null) { cx.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="result"></param> protected void GetResponseCallback(IAsyncResult result) { DataReceiveContext cx = null; try { cx = (DataReceiveContext)result.AsyncState; if (this.Socket == null) { throw new SocketClientException("Connection is closed"); } Int32 size = Stream.EndRead(result); TimeSpan ts = DateTime.Now - cx.StartTime; if (ts.TotalMilliseconds > this.ReceiveTimeout) { cx.Timeout = true; this.GetResponseDone.Set(); } if (cx.ReadBuffer(size) == true) { var bb = cx.GetByteArray(); this.Stream.BeginRead(bb, 0, bb.Length, this.GetResponseCallback, cx); } else { this.GetResponseDone.Set(); } } catch (Exception ex) { cx.Exception = ex; } if (cx.Exception != null) { try { this.GetResponseDone.Set(); } catch (ObjectDisposedException) { } } }