public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout, AsyncCallback callback, object state)
        {
            ThreadTrace.Trace("BC:BeginWrite");
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            this.Flush(timeoutHelper.RemainingTime());
            return(base.BeginWrite(buffer, offset, size, immediate, timeoutHelper.RemainingTime(), callback, state));
        }
 private void FlushCore(TimeSpan timeout)
 {
     if (this.pendingWriteSize > 0)
     {
         ThreadTrace.Trace("BC:Flush");
         base.Connection.Write(this.writeBuffer, 0, this.pendingWriteSize, false, timeout);
         this.pendingWriteSize = 0;
     }
 }
 public override void Write(byte[] buffer, int offset, int size, bool immediate, TimeSpan timeout)
 {
     if (size <= 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("size", (object)size, Microsoft.ServiceBus.SR.GetString(Resources.ValueMustBePositive, new object[0])));
     }
     this.ThrowPendingWriteException();
     if (immediate || this.flushTimeout == (long)0)
     {
         ThreadTrace.Trace("BC:Write now");
         this.WriteNow(buffer, offset, size, timeout);
     }
     else
     {
         ThreadTrace.Trace("BC:Write later");
         this.WriteLater(buffer, offset, size, timeout);
     }
     ThreadTrace.Trace("BC:Write done");
 }
 private void OnFlushTimer(object state)
 {
     ThreadTrace.Trace("BC:Flush timer");
     lock (this.ThisLock)
     {
         try
         {
             this.FlushCore(this.pendingTimeout);
             this.pendingTimeout = TimeSpan.Zero;
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             this.pendingWriteException = exception;
             this.CancelFlushTimer();
         }
     }
 }
 public override void EndWrite(IAsyncResult result)
 {
     ThreadTrace.Trace("BC:EndWrite");
     base.EndWrite(result);
 }