public static PerformanceStats From(IndexingOperation name, long durationMs) { return(new PerformanceStats { Name = name, DurationMs = durationMs }); }
private void EnqueueIndexingOperation(ModelObject modelObject, IndexingOperation indexingOperation) { lock (this.indexingQueue) { IndexingOperation pendingOperation; if (this.indexingQueue.TryGetValue(modelObject, out pendingOperation)) { if (indexingOperation != pendingOperation) { this.indexingQueue.Remove(modelObject); } } else { this.indexingQueue.Add(modelObject, indexingOperation); } } this.Status = IndexingStatus.Indexing; this.queueResetEvent.Set(); }
public static PerformanceStats From(IndexingOperation name, long durationMs) { return new PerformanceStats { Name = name, DurationMs = durationMs }; }
// Starts a new thread that continuously indexes new search items // as they become available private void BeginIndexing() { // An anonymous method that loops and does the // indexing when appropriate ThreadStart index = delegate { while (true) { // Wait if there is no work to do this.queueResetEvent.WaitOne(); // Get the next indexing operation, if one is available ModelObject modelObject = null; IndexingOperation indexingOperation = IndexingOperation.Register; lock (this.indexingQueue) { // If there are no indexing operations available, set // the status to ready and wait for more work if (this.indexingQueue.Count == 0) { this.Status = IndexingStatus.Ready; this.queueResetEvent.Reset(); continue; } // Otherwise, dequeue the next work item else { foreach (KeyValuePair <ModelObject, IndexingOperation> entry in this.indexingQueue) { modelObject = entry.Key; indexingOperation = entry.Value; break; } if (modelObject != null) { this.indexingQueue.Remove(modelObject); } } } // Process the indexing operation if (modelObject != null) { if (indexingOperation == IndexingOperation.Register) { this.RegisterModelObject(modelObject); } else if (indexingOperation == IndexingOperation.Unregister) { this.UnregisterModelObject(modelObject); } } } }; // Create a new thread and start the indexing loop Thread thread = new Thread(index); thread.Name = "Search Engine Indexer"; thread.IsBackground = true; thread.Priority = ThreadPriority.BelowNormal; thread.Start(); }