private void UpdateLayer(Layer layer) { if (FilteredLayer == null || !LayerAutoUpdateBehavior.IsLayerAutoUpdateCapable(layer)) { return; } if (layer.Dispatcher.CheckAccess()) { UpdateLayerUI(layer); } else { layer.Dispatcher.BeginInvoke(new AutoUpdateRefreshDelegate(UpdateLayerUI), layer); } }
/// <summary> /// Method that is called on the Main UI thread /// </summary> private void UpdateLayerUI(Layer layer) { // verify the layer has not been removed from the map already if (ParentBehavior == null || !ParentBehavior.MapContainsLayer(layer)) { return; } if (layer != null && LayerAutoUpdateBehavior.IsLayerAutoUpdateCapable(layer)) { try { if (layer is FeatureLayer) { // We only need to make sure the client caching is off while we // do this update, and then return it to the original state. bool cachingDisabled = ((FeatureLayer)layer).DisableClientCaching; if (!cachingDisabled) { ((FeatureLayer)layer).DisableClientCaching = true; } ((FeatureLayer)layer).Update(); if (!cachingDisabled) { ((FeatureLayer)layer).DisableClientCaching = false; } } else if (layer is ArcGISDynamicMapServiceLayer) { // We only need to make sure the client caching is off while we // do this update, and then return it to the original state. bool cachingDisabled = ((ArcGISDynamicMapServiceLayer)layer).DisableClientCaching; if (!cachingDisabled) { ((ArcGISDynamicMapServiceLayer)layer).DisableClientCaching = true; } ((ArcGISDynamicMapServiceLayer)layer).Refresh(); if (!cachingDisabled) { ((ArcGISDynamicMapServiceLayer)layer).DisableClientCaching = false; } } else if (layer is ICustomGraphicsLayer) { ((ICustomGraphicsLayer)layer).Update(); } } catch (Exception ex) { Console.WriteLine("Layer Update failed. " + ex); } _refreshRunning = false; // start the timer back up if the layer is still using auto updates if (LayerExtensions.GetAutoUpdateInterval(layer) > 0.0) { StartRefreshTimer(); } } }