Why is Lucene.Net indexer throwing a System.IO.IOException was unhandled?

坚强是说给别人听的谎言 提交于 2019-12-05 07:56:59

Assuming that the code presented is relevant to the search procedure (not the indexing procedure), you shouldn't try to delete the lock file every single time you try to access the index. The exceptions are being thrown because the background threads are currently writing to the index, and you are arbitrarily trying to delete its lock file when the thread itself should handle the deletion.

In the article you posted, this mechanism is used to recover the Lucene index after a system/application crash while it was writing the index, leaving it locked. However, this is hardly the common case. I believe that in the CodeProject article it is assumed a single-thread access to the index, hence the approach it takes.

In your project, you need to be able to check whether the existence of the lock file is due to current write access or to a previous application/system crash. You can use a lock object in your code, which is dynamically freed in the event of a crash, to discriminate between the two cases.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!