ThinkGeo.com    |     Documentation    |     Premium Support

MoveUp/MoveDown thread safety

I've recently encountered an issue working with layer reorganisation. Rapidly calling MoveUp() or MoveDown() causes an InvalidOperationException; the cause appears to be an unsynchronised collection and a callback which is busy reading the collection when the next MoveX call comes in. I'm confused as to why the code appears to be trying to redraw the layers though.


{"Collection was modified; enumeration operation may not execute."}


 Stack trace is as follows:



   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.DesktopEdition.LayerOverlay.xa6cb874f7090c07f(GeoCanvas x31c084515ae9393f)
   at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)
   at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)
   at ThinkGeo.MapSuite.DesktopEdition.xf0380b1a0bc40ca6.StartDraw()
   at ThinkGeo.MapSuite.DesktopEdition.x601a5561df898600.x7510a5c148e0acfd(Object x19b0b2213afc2289)
   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)

Same thing here, exact same stack. Layers are not re-arranged in my case, though – it’s just zoom and pan operations, performed quickly.  
  
   


Janet and Fedor, 
  
 I couldn’t recreate this issue. Are you using multi-threading? Can you provide some codes or demo to help us recreate this? 
  
 Thanks, 
  
 Ben 


No, definitely not using multithreading. I’ll put a demo app together later and attach it.

The demo app is too large to attach, so please download it from here: africonit.co.za/AfriconDemo/ThinkGeoCrashDemo1.zip (4.8 MB)


 


Ensure that the app is maximised before clicking "Cause Crash", as it is dependent on the map taking some time to draw itself. If you click "Load Layers" first, then the Cause Crash button no longer causes a crash.






 

 


Janet,


You are using 3.0.180, I changed it to the latest public release 3.0.199 and everything is fine. Please add the following code in the Form1() method to make sure it is using the latest version.



string version = WinformsMap.GetVersion();
if (!version.Contains("3.0.199"))
{
throw new Exception("version not right");
}


Thanks,


Ben


 



Oh, dear. I have no idea how I overlooked that it wasn’t the latest version. I’ll re-test with the newer one, thanks.

That happens:) Let me know if you have more issues. 
  
 Ben.