Hi
I'm having some problems with the map control, if i make some updates to an layer, and the user make some interaction with the control at same time (layer drawing is active) the lock dosent seems to work.
FATAL..: An application error occurred.
DETAILS: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)
at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x5021a7a45adbb9ee(Object x3faa3e674cef60b0)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
sample code of how i lock the layer.
First i remove items from the layer, and then request some new point async.
winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.EnterWriteLock();
try
{
InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)winMap.FindFeatureLayer(GetLayerName(LayerNameEnum.RepYear));
pointLayer.InternalFeatures.Clear();
ValueStyle valueStyle = new ValueStyle();
valueStyle.ColumnName = "RepValue";
valueStyle.IsActive = true;
m_themeManager.SetCurrentThemeAndParameter(m_colorThemeForm.GetSelectedTheme(), m_parameterToShow);
for (int i = 0; i <= 100; i++)
{
//Color color = repLayerSettingsControl.GetColorByPercent(i);
Color color = m_themeManager.GetCurrentColorByPercent(i);
valueStyle.ValueItems.Add(new ValueItem(i.ToString(),
new PointStyle(PointSymbolType.Circle,
new GeoSolidBrush(GeoColor.FromArgb(color.A, color.R, color.G, color.B)), 5)));
}
pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
pointLayer.BuildIndex();
}
finally
{
winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.ExitWriteLock();
}
Code for inserting new points.
winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.EnterWriteLock();
try
{
InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)winMap.FindFeatureLayer(GetLayerName(LayerNameEnum.RepYear));
int index = 0;
double factor = (m_currentParameterMaxValue - m_currentParameterMinValue);
foreach (MesoRepresentativeItem item in e.Items)
{
index++;
GeoCoordinate gc = ConvertFromDecimalDegreeToMeters(item.Longitude, item.Latitude);
Feature feature = new Feature(gc.Longitude, gc.Latitude,
item.GetHashCode().ToString() + index);
int value = Convert.ToInt32(Math.Round(m_themeManager.GetCurrentPercentByValue(m_currentValues[index - 1])));
feature.ColumnValues.Add("RepValue", value.ToString());
pointLayer.InternalFeatures.Add(item.GetHashCode().ToString() + index, feature);
}
pointLayer.BuildIndex();
pointLayer.IsVisible = true;
Console.Out.WriteLine("Added Rep: " + e.Items.Count);
}
catch (Exception ex)
{
Console.Out.WriteLine(ex.Message);
}
finally
{
winMap.Overlays[GetLayerName(LayerNameEnum.RepYear)].Lock.ExitWriteLock();
}
winMap.Refresh();
Any idea ?