I have a need for two seperate threads that access a ShapeFileFeatureLayer; however, once I create the ShapeFileFeatureLayer in the first thread, I can no longer open it in the second thread because it gives me that the shape file is being used by another process. Is there a way around this?
System.IO.IOException was caught
Message=The process cannot access the file ‘user_areas.shp’ because it is being used by another process.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access)
at ThinkGeo.MapSuite.Core.ShapeFile.URg=(FileAccess SkM=)
at ThinkGeo.MapSuite.Core.ShapeFileFeatureSource.ZxQ=()
at ThinkGeo.MapSuite.Core.ShapeFileFeatureSource.OpenCore()
at ThinkGeo.MapSuite.Core.FeatureSource.Open()
at ThinkGeo.MapSuite.Core.FeatureLayer.OpenCore()
at ThinkGeo.MapSuite.Core.Layer.Open()
Thread 1 (GUI Thread that draws my map)
if
(!File.Exists(STORED_USER_AREAS_FILENAME))
{
Collection<DbfColumn> dbf_columns =
new
Collection<DbfColumn>();
dbf_columns.Add(
new
DbfColumn(STORED_USER_AREAS_NAME_COLUMN, DbfColumnType.String, 255, 0));
ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, STORED_USER_AREAS_FILENAME, dbf_columns, System.Text.Encoding.ASCII, OverwriteMode.Overwrite);
}
ShapeFileFeatureLayer layer =
new
ShapeFileFeatureLayer(STORED_USER_AREAS_FILENAME, ShapeFileReadWriteMode.ReadWrite);
layer.Name =
“Stored User Areas”
;
// Set the display style of the stored areas:
layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =
new
AreaStyle(
new
GeoPen(
new
GeoColor(255, 255, 165, 0), 2.0f),
new
GeoSolidBrush(
new
GeoColor(75, 255, 165, 0)));
// Set the text style of the stored areas:
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(STORED_USER_AREAS_NAME_COLUMN,
“Arial”
, 10, DrawingFontStyles.Bold, GeoColor.SimpleColors.Black);
layer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping;
// Display stored areas at all zoom levels:
layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
m_dynamic_overlay.Layers.Add(layer.Name, layer);
m_layer_stored_user_areas = layer;
if
(layer.IsOpen) layer.Close();
Thread 2 (Background Thread that need access to the information in that shape file)
m_layer_stored_user_areas =
new
ShapeFileFeatureLayer(STORED_USER_AREAS_FILENAME, ShapeFileReadWriteMode.ReadWrite);
m_layer_stored_user_areas.Open();
Collection<Feature> features = m_layer_stored_user_areas.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
m_layer_stored_user_areas.Close();
Thank you,
Treasa