protected virtual void QueryStorage(List <int> activeDeliveryTypes) { //update query state _lastQueryTimeUtc = DateTime.UtcNow; _lastQueryKeys = activeDeliveryTypes; _isLastQueryMaxItemsReceived = false; //query items Stopwatch storageQueryTimer = Stopwatch.StartNew(); DateTime lockStartUtc = DateTime.UtcNow; List <SignalDispatch <TKey> > items = null; try { items = PickStorageQuery(activeDeliveryTypes); } catch (Exception ex) { items = new List <SignalDispatch <TKey> >(); _logger.LogError(ex, SenderInternalMessages.DatabaseDispatchProvider_DatabaseError); } storageQueryTimer.Stop(); //enqueue items for processing _dispatchQueue.Append(items, true); //turn on database event tracking _isLastQueryMaxItemsReceived = items.Count == ItemsQueryCount; if (_changeNotifier != null && _isLastQueryMaxItemsReceived == false) { _changeNotifier.StartMonitor(); } //store metrics _monitor.DispatchPersistentStorageQueried(storageQueryTimer.Elapsed, items); //remember processed items, not to query them again while processing _lockTracker.RememberLock(items.Select(x => x.SignalDispatchId), lockStartUtc); }