Hi,
I'm trying to go through each layer in the TOC and do get the alias name of the layer then do something that name. In order to this - I have a recursive method that loops - however you need to await QueuedTask.Run() the call to get information about an alias in layer - and in a recursive function something weird is happening - as this only gets called once and never breaks into that Queued Task code block again.
Something is happening here thats a bit beyond me when it gets to asynchronous programming - can anyone help me find a way to get this recursive function to work properly?
//calling code:
var map = MapView.Active.Map;
foreach (var item in map.Layers)
{
await RecurseTocLayers(item);
}
private async Task RecurseTocLayers(Layer layer)
{
if (layer is BasicFeatureLayer)
{
FeatureLayer featureLayer = layer as FeatureLayer;
//THIS ONLY GETS CALLED ONCE - THEN NEVER AGAIN!
await QueuedTask.Run(() =>
{
var table = featureLayer.GetTable();
TableDefinition tableDefinition = table.GetDefinition();
string alias = tableDefinition.GetAliasName();
//do something here with alias name.....e.g.
System.Diagnostics.Debug.WriteLine($"The alias name is: {alias}");
});
}
if (layer is GroupLayer)
{
//do something here with GroupLayer, then....
GroupLayer groupLayer = (GroupLayer)layer;
foreach (var child in groupLayer.Layers)
{
await RecurseTocLayers(child);
}
}
}
ASDFDSAF