Hello,
I have used method of ShapeFileFeatureLayer to build Index file of shape file. And also set Build Index mode to Rebuild like
ShapeFileFeatureLayer.BuildIndexFile(shapeFilePath, BuildIndexMode.Rebuild);
Now I have OSM and bing map layer with the map. I load local map at the time of Map load and add another layer of OSM or Bing based on user selection. Now when I come back to local map from OSM or Bing at that time when it execute above line of code it gives me error(Exception) like
Index file is already in used. So is there any method to remove this error and build Index file again when I switch between other layer to Local layer.
Thank you
Eric.
Issue with Build Index file
Hi Eric,
Would you please let us know your scenarios or attached some codes to show why you want to rebuild the index file after switch back to the local map?
Even don’t sure your case, but from the exception, it says some shapefile layer instance is using the files, so, we can call the layer.Close method to cut off the file stream before buiding the index files. like shapefileFeatureLayer.Close()
Please let us know if the issue persists.
Thanks,
Troy
Hi Eric,
Would you please let us know your scenarios or attached some codes to show why you want to rebuild the index file after switch back to the local map?
Even don’t sure your case, but from the exception, it says some shapefile layer instance is using the files, so, we can call the layer.Close method to cut off the file stream before building the index files. like shapefileFeatureLayer.Close()
Please let us know if the issue persists.
Thanks,
Troy
Hello Troy,
Thank you for your reply. I have created one method to render Local map using different shape files. Now in that method I have added code for Building Index file
ShapeFileFeatureLayer.BuildIndexFile(shapeFilePath, BuildIndexMode.Rebuild);
Now when I switch between OSM or Bing to Local map I call method to remove all Overlays before calling method to render Local map. and again in Local map method there is code to build index file again. and at that time it gives me Exception for Index file is in use.
and I have around above 20 shape files that I am rendering in local map. and it getting updated at some time so if we forgot to update/create index file for that shape file at that time it gives error for that so for we added method to build index file while rendering that shape file.
So when I can call function shapefileFeatureLayer.Close() to close that shape file.? means at the end of Local method because at that time I can get all object of shapefileFeatureLayer.
Please let me know about this.
Thank you.
Eric.
Hi Eric,
In fact you don’t need rebuild index unless the file without index file or the shape file have been modified. So I think you can check the index file status first then decide whether build the index file for it, this can also improve performance of your program.
And if you have started to render a layer, include call layer.Open() or call map refresh function. The index file keep using status now. So you have to close the layer to stop program use the index file first then rebuild the index file.
So if you need rebuild index file, please close related layer, then refresh map again.
Regards,
Don
Eric,
The key is that you need to call the .Close on the layer. Remember if you see anything in MapSuite that has a .Open or .Close you need to make sure to close it. Having this means that most likely we are accessing resources that need to be freed.
David