Select to view content in your preferred language

how to wait unitl layer creation is complete?

06-22-2017 02:09 PM
New Contributor II

Hi, I am adding a layer to a map and want to read all the values from a particular field,


await QueuedTask.Run(() =>
                    Layer RefLayer = LayerFactory.CreateLayer(new Uri(LyrFile), myMap);
                    if (RefLayer == null)
                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Failed to create layer for url:" + LyrFile);


                       //find layer
                      var disLayer = MapView.Active.Map.FindLayers(layerName).FirstOrDefault() as BasicFeatureLayer;





however the FindLayers returns null.

What would be an appropriate way to wait until the creation is done?

Can someone help me solve this?

0 Kudos
2 Replies
Esri Regular Contributor

I cannot reproduce this. It works for me.

A couple of things which may just be copy-paste issues into the post....

1. You add the layer to "myMap"

2. You attempt to retrieve it from MapView.Active.Map? Are they the same?


does RefLayer.Name == layerName? I can't tell from your code.

Is the layer a BasicFeatureLayer?

New Contributor II

Thank you Charles.  Yes, myMap is the MapView.Active.Map and RefLayer.Name is the layerName.

Your questions helped me find out what the problem was: I was handling the creation in a queued task and FindLayers outside that task. I'm new to C# so I haven't really grasped how the queued tasks work. Thanks again!

0 Kudos