public void RunProcess() { // this operation will perform lock, get, release lock in one go if (_lockManager.TryLockAndGet(lockKey: _getFileLockKey, msTimeout: _lockMsTimeout, get: () => _dataRepository.GetNextItemsToProcess(_itemsToFetchAtATime), output: out IEnumerable <IDataObject> itemsToProcess)) { if (itemsToProcess.Any()) { // materialize the items var items = itemsToProcess.ToList(); // process foreach (var item in items) { _logger.Log(item.ToString()); } //Thread.Sleep(3000); // simulate some work // clean up _logger.Log("Finished processing, removing the data"); _dataRepository.DisposeItems(items); } } }