I created a map using C# and esri wpf.
We have an Excel add-in application that can open my map code. After my queryTask execute completed method is called, I invoked a method to add graphics to map. I got the following error when adding graphics to graphic layer: graphicMapLayer.Graphics.Add(graphic);
System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
I found a solution by calling Dispatcher.Invoke
e.g. this.Dispatcher.Invoke( new AddGraphicDelegate(AddGraphic), graphic);
private void AddGraphic(Graphic g)
{
graphicMapLayer.Graphics.Add(g);
}
However, after I got the above problem fixed, I got another thread exception for another arcgis method as following:
at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
at ESRI.ArcGIS.Client.Graphic.get_Visibility()
at ESRI.ArcGIS.Client.GraphicsLayer.RenderGraphics(Double resolution, MapPoint canvasOrigin, Envelope env, Envelope bufferedExtent, IEnumerable`1 gfxs, Boolean isClustering, IRenderer renderer, Boolean interactive)
at ESRI.ArcGIS.Client.GraphicsLayer.Draw(Envelope extent, Double resolution, MapPoint canvasOrigin, Boolean useTransitions)
at ESRI.ArcGIS.Client.Map.loadLayerInView(Boolean useTransitions, Envelope drawExtent, Layer layer)
at ESRI.ArcGIS.Client.Map.loadLayersInView(Boolean useTransitions, Envelope drawExtent)
at ESRI.ArcGIS.Client.Map.panTo(Geometry geometry, Boolean skipAnimation)
at ESRI.ArcGIS.Client.Map.zoomTo(Geometry geom, Boolean skipAnimation)
at ESRI.ArcGIS.Client.Map.set_Extent(Envelope value)
Please help! I don't know where is the right place to call Invoke() in this case that handles all arcgis calls.
Thanks!