Problem
DatabaseLogger._allSessionPoints (and its contained List<DataPoint> values) is written on a background thread during DisplayLoggingSession / LoadSampledData (Phase 2) while simultaneously being read on the UI thread by UpdateMainPlotViewport, UpdateSeriesFromMemory, ResetZoom, and FetchViewportDataFromDb.
This can cause InvalidOperationException (collection modified during enumeration), ArgumentOutOfRangeException (index into a list that was cleared), or corrupted data during pan/zoom while a session is loading.
Identified in
PR #467 double-check audit and Qodo review comment #2.4.
Suggested approaches (pick one)
- Single-thread ownership: Build all point data in local structures on the background thread, then
Dispatcher.Invoke once to swap _allSessionPoints references on the UI thread.
- Locking: Add a
lock(_sessionPointsLock) around all reads/writes/iterations of _allSessionPoints and contained lists.
- Pause viewport timers: Stop
_viewportThrottleTimer during Phase 2 loading and restart after data is stable.
Option 1 is cleanest — it eliminates the shared mutable state entirely.
Files involved
Daqifi.Desktop/Loggers/DatabaseLogger.cs — DisplayLoggingSession, LoadSampledData, UpdateMainPlotViewport, UpdateSeriesFromMemory, ResetZoom, PrepareMinimapData
Problem
DatabaseLogger._allSessionPoints(and its containedList<DataPoint>values) is written on a background thread duringDisplayLoggingSession/LoadSampledData(Phase 2) while simultaneously being read on the UI thread byUpdateMainPlotViewport,UpdateSeriesFromMemory,ResetZoom, andFetchViewportDataFromDb.This can cause
InvalidOperationException(collection modified during enumeration),ArgumentOutOfRangeException(index into a list that was cleared), or corrupted data during pan/zoom while a session is loading.Identified in
PR #467 double-check audit and Qodo review comment #2.4.
Suggested approaches (pick one)
Dispatcher.Invokeonce to swap_allSessionPointsreferences on the UI thread.lock(_sessionPointsLock)around all reads/writes/iterations of_allSessionPointsand contained lists._viewportThrottleTimerduring Phase 2 loading and restart after data is stable.Option 1 is cleanest — it eliminates the shared mutable state entirely.
Files involved
Daqifi.Desktop/Loggers/DatabaseLogger.cs—DisplayLoggingSession,LoadSampledData,UpdateMainPlotViewport,UpdateSeriesFromMemory,ResetZoom,PrepareMinimapData