.net – Error while copying Lucene index


I've an asp.net web application which uses Lucene API for search.
Here is the problem scenario:


  1. User invokes a Lucene search query thru the web application.
  2. There is another windows service running which just copies the search index folder to another folder.

When event 2 occurs after event 1 has occurred, I am getting error below while copying the index:

The process cannot access the file 'C:\Indexes\segments.gen'
because it is being used by another process.

What am i missing here?

FYI, am using System.IO.File.Copy with overwrite set to true to copy index files.

Best Solution

The problem is because the first event locks Lucine files, You can create 2 copies of the same index, and synchronize you processes to not prevent each other