protected virtual void Dispose(bool disposing) { lock (padlock) { if (disposed == false) { SerializeItemsToIndex(); if (disposing) { if (indexSearcher != null) { indexSearcher.Dispose(); } if (IndexWriter != null) { IndexWriter.Dispose(); } if (IndexDirectory != null) { IndexDirectory.Dispose(); } } // Indicate that the instance has been disposed. IndexWriter = null; indexSearcher = null; IndexDirectory = null; disposed = true; } } }
private async Task StartNewEngineAsync(string name, string path) { var sb = new StringBuilder(); var console = new StringWriter(sb); var indexDirectory = new IndexDirectory(name, path); var engine = new Lucene29LocalIndexingEngine(indexDirectory); SnTrace.Write("100 starting"); await engine.StartAsync(console, false, CancellationToken.None).ConfigureAwait(false); SnTrace.Write("101 started"); while (!File.Exists(indexDirectory.IndexLockFilePath)) { Task.Delay(50).ConfigureAwait(false).GetAwaiter().GetResult(); } await engine.ShutDownAsync(CancellationToken.None).ConfigureAwait(false); }
static void Main(string[] args) { try { var delay = int.Parse(args[0]); var name = args[1]; var path = args[2]; var indexDirectory = new IndexDirectory(name, path); var engine = new Lucene29LocalIndexingEngine(indexDirectory); engine.StartAsync(null, false, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); Task.Delay(delay).ConfigureAwait(false).GetAwaiter().GetResult(); engine.ShutDownAsync(CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Press <enter> to exit..."); Console.ReadLine(); }
private async Task <(string Name, string Path, string LockPath)> EnsureIndexDirectoryAsync() { var indexDirectory = new IndexDirectory("WriteLockTests", null); var engine = new Lucene29LocalIndexingEngine(indexDirectory); await engine.StartAsync(null, false, CancellationToken.None).ConfigureAwait(false); while (!File.Exists(indexDirectory.IndexLockFilePath)) { Task.Delay(50).ConfigureAwait(false).GetAwaiter().GetResult(); } await engine.ShutDownAsync(CancellationToken.None).ConfigureAwait(false); while (File.Exists(indexDirectory.IndexLockFilePath)) { Task.Delay(50).ConfigureAwait(false).GetAwaiter().GetResult(); } var name = indexDirectory.Name; var path = Path.GetDirectoryName(indexDirectory.CurrentDirectory); return(name, path, indexDirectory.IndexLockFilePath); }