private void DoWork() { while (!shutdown) { IndexQueueItem item = null; try { if (_indexQueue.Queue.TryDequeue(out item)) { try { //_logger.LogDebug("Dequeued item - " + item.EntityID); //IIndexStore indexStore = _services.GetService<IIndexStore>(); IIndexStore indexStore = IoC.Container.Resolve <IIndexStore>(); IDbContext primaryDC = (IoC.Container.Resolve(item.ContextType) as IDbContext); IIndexBuilder indexer = new IndexBuilder(indexStore, primaryDC, _indexQueue, _registry); //TODO: fix indexer.IndexEntity(item.EntityType, item.EntityID, item.Recursive, item.ContextType); indexStore.SaveChanges(); indexStore.Dispose(); primaryDC.Dispose(); } catch (OptimisticConcurrencyException ex) { _indexQueue.Queue.Enqueue(item); //_logger.LogError("Error indexing (" + item.EntityType + ", " + item.EntityID.ToString() + "): " + ex.Message, ex); } catch (Exception ex) { //todo: add error reporting //_logger.LogError("Error indexing (" + item.EntityType + ", " + item.EntityID.ToString() + "): " + ex.Message, ex); } } else { System.Threading.Thread.Sleep(500); //no work } } catch (Exception ex) { //todo: add error reporting //_logger.LogError("Error indexing (" + item.EntityType + ", " + item.EntityID.ToString() + "): " + ex.Message, ex); } } }