AnsweredAssumed Answered

Application crashes randomly when updating Kml Layer

Question asked by jasonMDSP on Sep 3, 2015
Latest reply on Sep 23, 2015 by jasonMDSP

I have a piece of code that updates a KML overlay often. Some times, at random, my application crashes after replacing the KML layer from my Scene. I do not get an error message, not does it let me debug it, so I suspect is somewhere in the ArcGis code. Is this the correct way to update a KML layer?

 

string id = objId + "Overlay";

System.IO.File.WriteAllText(_tempFilePath + @"\" + id + ".kml", kmlString);
var sourceUri = new Uri(_tempFilePath + @"\" + id + ".kml"); //I receive KML as a string, so I save as a file to get an URI

if (MySceneView.Scene.Layers[id] == null) //first time adding the layer
  {
     var kmlLayer = new KmlLayer(sourceUri);
     kmlLayer.ID = id;
     kmlLayer.Opacity = _alpha;
     MySceneView.Scene.Layers.Add(kmlLayer);
     return id;
  }
  else //Update the layer
  {
     for(int i = MySceneView.Scene.Layers.Count - 1; i >= 0; i--)//for each layer
     {
        if (MySceneView.Scene.Layers[i].ID == id) //find the matching ID
        {
           var kmlLayer = new KmlLayer(sourceUri);
           kmlLayer.ID = id;
           kmlLayer.Opacity = _alpha;
   
           MySceneView.Scene.Layers[i] = kmlLayer; //repalce the layer with the updated one
           return id;
        }
     }
  }

return "";

Outcomes