/// <summary> /// Starts writing period handled and terminated data to this stream. /// </summary> /// <param name="op">Asynchronous operation.</param> /// <returns>Returns true if aynchronous operation is pending (The <see cref="WritePeriodTerminatedAsyncOP.CompletedAsync"/> event is raised upon completion of the operation). /// Returns false if operation completed synchronously.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception> /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception> public bool WritePeriodTerminatedAsync(WritePeriodTerminatedAsyncOP op) { if(this.m_IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(op == null){ throw new ArgumentNullException("op"); } if(op.State != AsyncOP_State.WaitingForStart){ throw new ArgumentException("Invalid argument 'op' state, 'op' must be in 'AsyncOP_State.WaitingForStart' state.","op"); } return op.Start(this); }
/// <summary> /// Writes period handled and terminated data to this stream. /// </summary> /// <param name="stream">Source stream. Reading starts from stream current location.</param> /// <returns>Returns number of bytes written to stream.</returns> /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception> /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> is null.</exception> /// <exception cref="LineSizeExceededException">Is raised when <b>stream</b> has too big line.</exception> public long WritePeriodTerminated(Stream stream) { if(m_IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(stream == null){ throw new ArgumentNullException("stream"); } ManualResetEvent wait = new ManualResetEvent(false); WritePeriodTerminatedAsyncOP op = new WritePeriodTerminatedAsyncOP(stream); op.CompletedAsync += delegate(object s1,EventArgs<WritePeriodTerminatedAsyncOP> e1){ wait.Set(); }; if(!this.WritePeriodTerminatedAsync(op)){ wait.Set(); } wait.WaitOne(); wait.Close(); if(op.Error != null){ throw op.Error; } else{ return op.BytesWritten; } }