示例#1
0
        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;
        }
示例#2
0
        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();
            }
        }
示例#3
0
            public void Dispose()
            {
                if (FlushTimer != null)
                {
                    FlushTimer.Dispose();
                    FlushTimer = null;
                }

                if (Link != null)
                {
                    Link.Dispose();
                    Link = null;
                }
            }
示例#4
0
 public bool StopStreaming()
 => IsStreaming = !FlushTimer.Change(Timeout.Infinite, Timeout.Infinite);
示例#5
0
 public bool StartStreaming(int period = 50)
 => IsStreaming = FlushTimer.Change(0, period);
示例#6
0
 protected virtual void Flush(object sender, ElapsedEventArgs e)
 {
     BytesWrittenSinceLastFlush = 0;
     FlushTimer.Stop();
     Writer.Flush();
 }
示例#7
0
 public void Dispose()
 {
     FlushTimer?.Dispose();
     LogWriter?.Flush();
     LogWriter?.Dispose();
 }