Te application I'm developing needs to dynamically create RadMap controls, and then dispose them after they are no longer required. The map typically has several layers (both InformationLayer and VisualizationLayer types). The ItemsSource property of each layer is typically bound to an observable collection. Some background threads are responsible for getting data and adding to the appropriate layer's observable collection (invoking onto the dispatcher thread if required). This approach all works well most of the time but occasionally when the RadMap is disposed we get an exception which crashes the application:
Telerik.Windows.Controls.DataVisualization : System.NullReferenceException
Object reference not set to an instance of an object.
at Telerik.Windows.Controls.Map.MapShapeData.SetLogicalWidth(Int32 zoomLevel)
at Telerik.Windows.Controls.Map.MapShapeData.CalculateScreenGeometry(Int32 zoomLevel, Boolean raisePropertyChanged)
at Telerik.Windows.Controls.Map.ShapeCoordinatesProcessor.StartProcessing(Object paramObject)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
The stack trace shows that it's happening on a background thread (i.e. not the thread I'm calling dispose on) and does not reference any of my code. Unfortunately I've not yet been able to replicate this in a simpler application but I'm hoping you may be able to suggest what I am doing wrong - is there a particular approach I need to take when disposing the map? I've tried various things, including stopping my background processing threads before disposal but so far I've not been able to fix the problem. The fact that the problem happens intermittently might suggest that there is a timing issue.
Can you suggest anything I should try?