I'm using a concurrentDictionary instance:
private ConcurrentDictionary<string, ConcurrentResource> concurrentResources;
, where:
private class ConcurrentResource
{
private int counter;
private FlexLucene.Index.IndexWriter writer;
}
I only want to store a counter for getting how many threads are using the IndexWriter
.
private FlexLucene.Index.IndexWriter toggleIndexWriter(System.IO.DirectoryInfo directory)
{
IndexEngine.ConcurrentResource concurrentResource = this.concurrentResources.AddOrUpdate(
directory.FullName,
(directoryPath) =>
{
********************************
FlexLucene.Index.IndexWriter writer = this.createIndexWriter(directoryPath);
return new IndexEngine.ConcurrentResource(writer);
********************************
},
(directoryPath, internalConcurrentResource) =>
{
if (!internalConcurrentResource.Writer.IsOpen())
internalConcurrentResource.Writer = this.createIndexWriter(directoryPath);
internalConcurrentResource.Counter += 1;
return internalConcurrentResource;
}
);
return concurrentResource.Writer;
}
It baffles me that I'm using two threads, and debugging I've realized both threads are performing the lines marked as ************************
.
Any ideas?