private void DoWork() { // lock chunk lock (_chunkBytes) { if (!_needToFlush) { return; } try { if (_compression != null && _chunkLength >= CompressionThreshold && TryCompress(out var written)) { WriteChunk(_chunkCompressedBytes, written, true); } else { WriteChunk(_chunkBytes, _chunkLength, false); } } catch (Exception exception) { _flushException = exception; } _flushStopwatch.Start(); _needToFlush = false; } UpdateHasWork(); }
public void Flush() { if (_totalCount <= 0) { return; } _logger.Log(_totalCount == 1 ? $"Sent {_lastChange} in {(int)_timeSpan.TotalMilliseconds} ms" : $"Sent {_totalCount} changes, {PrettySize(_totalSize)} in {(int)_timeSpan.TotalMilliseconds} ms"); _lastChange = ""; _totalCount = 0; _totalSize = 0; _timeSpan = TimeSpan.Zero; _stopwatch.Start(); }