protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { _cancellationTokenSource?.Cancel(); FlushTimer?.Stop(); if (FlushTimer != null) { FlushTimer.Elapsed -= Flush; } FlushTimer?.Dispose(); Reader?.Close(); Reader?.Dispose(); Writer?.Close(); Writer?.Dispose(); OverridableDispose(); } disposed = true; }
public virtual void Write(byte[] bytes) { int bytePointer = 0; int bytesLeft = bytes.Length; bool hasFlushed = false; while (bytesLeft > 0) { int count = Math.Min(_maxBytesPerWrite, bytesLeft); Writer.Write(bytes, bytePointer, count); BytesWrittenSinceLastFlush += count; if (BytesWrittenSinceLastFlush >= 200) { // Immediately trigger a flush before proceeding so the output buffer will not be delayed. hasFlushed = true; Flush(null, null); } bytePointer += count; bytesLeft -= count; } if (!hasFlushed) { FlushTimer?.Start(); } }
public void Dispose() { if (FlushTimer != null) { FlushTimer.Dispose(); FlushTimer = null; } if (Link != null) { Link.Dispose(); Link = null; } }
public bool StopStreaming() => IsStreaming = !FlushTimer.Change(Timeout.Infinite, Timeout.Infinite);
public bool StartStreaming(int period = 50) => IsStreaming = FlushTimer.Change(0, period);
protected virtual void Flush(object sender, ElapsedEventArgs e) { BytesWrittenSinceLastFlush = 0; FlushTimer.Stop(); Writer.Flush(); }
public void Dispose() { FlushTimer?.Dispose(); LogWriter?.Flush(); LogWriter?.Dispose(); }