Problem
DatabaseLogger.Consumer() runs a while (true) loop with no cancellation mechanism. When Dispose() is called, it disposes the BlockingCollection<DataSample> _buffer, which causes the consumer thread to throw ObjectDisposedException. The exception is caught and logged, but the while(true) loop continues — now repeatedly calling .Count on a disposed collection, logging errors in an infinite loop until the process exits.
Impact
- Resource leak: consumer thread never terminates
- Log spam: infinite error logging after disposal
- Clean shutdown impossible
Suggested fix
- Add a
CancellationTokenSource _consumerCts field
- Change
while (true) to while (!_consumerCts.IsCancellationRequested)
- Use
_buffer.GetConsumingEnumerable(_consumerCts.Token) or check the token in the loop body
- In
Dispose(), cancel _consumerCts before disposing _buffer
- Optionally call
_buffer.CompleteAdding() to signal the consumer that no more items will arrive
Files involved
Daqifi.Desktop/Loggers/DatabaseLogger.cs — Consumer() method and Dispose()
Problem
DatabaseLogger.Consumer()runs awhile (true)loop with no cancellation mechanism. WhenDispose()is called, it disposes theBlockingCollection<DataSample> _buffer, which causes the consumer thread to throwObjectDisposedException. The exception is caught and logged, but thewhile(true)loop continues — now repeatedly calling.Counton a disposed collection, logging errors in an infinite loop until the process exits.Impact
Suggested fix
CancellationTokenSource _consumerCtsfieldwhile (true)towhile (!_consumerCts.IsCancellationRequested)_buffer.GetConsumingEnumerable(_consumerCts.Token)or check the token in the loop bodyDispose(), cancel_consumerCtsbefore disposing_buffer_buffer.CompleteAdding()to signal the consumer that no more items will arriveFiles involved
Daqifi.Desktop/Loggers/DatabaseLogger.cs—Consumer()method andDispose()