ThinkGeo.com    |     Documentation    |     Premium Support

Exception when removing items from feature layer

System.Transactions Critical: 0 : <TraceRecord xmlns="schemas.microsoft.com/2004/1...raceRecord" Severity="Critical"><TraceIdentifier>msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>VSUClientApplication.vshost.exe</AppDomain><Exception><ExceptionType>System.InvalidOperationException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Collection was modified; enumeration operation may not execute.</Message><StackTrace>   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)

   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()

   at System.Collections.Generic.List`1.Enumerator.MoveNext()

   at ThinkGeo.MapSuite.Core.ZoomLevel.DrawCore(GeoCanvas canvas, IEnumerable`1 features, Collection`1 currentLayerLabels, Collection`1 allLayerLabels)

   at ThinkGeo.MapSuite.Core.ZoomLevel.Draw(GeoCanvas canvas, IEnumerable`1 features, Collection`1 currentLayerLabels, Collection`1 allLayerLabels)

   at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)

   at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)

   at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.DrawOverlaysForMultiThread(Object drawingOverlaysObject)

   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(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)</StackTrace><ExceptionString>System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)

   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()

   at System.Collections.Generic.List`1.Enumerator.MoveNext()

   at ThinkGeo.MapSuite.Core.ZoomLevel.DrawCore(GeoCanvas canvas, IEnumerable`1 features, Collection`1 currentLayerLabels, Collection`1 allLayerLabels)

   at ThinkGeo.MapSuite.Core.ZoomLevel.Draw(GeoCanvas canvas, IEnumerable`1 features, Collection`1 currentLayerLabels, Collection`1 allLayerLabels)

   at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)

   at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)

   at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.DrawOverlaysForMultiThread(Object drawingOverlaysObject)

   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(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)</ExceptionString></Exception></TraceRecord>


When having an layer with no projection, map.unit in meters, and 14.400 points in an layer, the are grided 1km x 1km

zoom in and remove points from layer, sometimes gives the exception above.


Build 3.0.411


Code for making overlay:


        private LayerOverlay LoadPointLayer()

        {

            FeatureSourceColumn column = new FeatureSourceColumn("RepValue", "string", 101);

            Collection<FeatureSourceColumn> columns = new Collection<FeatureSourceColumn>();

            columns.Add(column);

            InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer(columns, new Feature[] { });

            pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay pointOverlay = new LayerOverlay();




            ValueStyle valueStyle = new ValueStyle();

            valueStyle.ColumnName = "RepValue";

            valueStyle.IsActive = true;


            for (int i = 0; i <= 100; i++)

            {

                Color color = repLayerSettingsControl.GetColorByPercent(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.Add(valueStyle);

            pointOverlay.Layers.Add("RepLayer", pointLayer);


            return pointOverlay;

        }


 


Code for remove:




            winMap.Overlays["RepLayer"].Lock.EnterWriteLock();

            try

            {

                InMemoryFeatureLayer pointLayer = (InMemoryFeatureLayer)winMap.FindFeatureLayer("RepLayer");

                

                pointLayer.InternalFeatures.Clear();


                ValueStyle valueStyle = new ValueStyle();

                valueStyle.ColumnName = "RepValue";

                valueStyle.IsActive = true;


                for (int i = 0; i <= 100; i++)

                {

                    Color color = repLayerSettingsControl.GetColorByPercent(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);


            }

            finally

            {

                winMap.Overlays["RepLayer"].Lock.ExitWriteLock();

            }


 


 


 


 



Lars, 
  
   I noticed you did not lock when you added the points.  Is it possible this is being called again?  Can you provide this in sample form?  I mean a small Winforms application that can be run and demonstrates the issue? E-mail it to support@thinkgeo.com and have it forwarded to David?  The code you provided looks good but I want to see the rest of it and I would like it in runnable form if possible.  Sometimes with threading issues it is the rest of things that effect it and not just what you think it is. 
  
 David

Hi 
  
 Is there an easy way to export points from a layer, and import them again, so that its  
 easy to provide you with the right data, without having to make imports from tekst files etc. ?

Lars, 
  
 We have public the latest version (4.0.415) in which we resolved some issues, could you try this version to see if this problem still exists? 
  
 Besides, we did not receive your sample codes (only sample data) to show your problem, and we reviewed the codes in the post and seem it lack a bunch of critical code snippets.  
  
 Any more questions just feel free to let me know. 
 Thanks. 
  
 Yale 


Lars, 
  
   Hmm…  You could loop through the point features and then get the Shape and get the Well Know text.  Just save each one to a line in a text file.  We can read that in pretty easily.  You can also create a shapefile for them and add then through the editing system.  If it is too much trouble we could always try it with some other point data we have.  I just wanted to be sure with your data. 
  
 David