I need to access a ListBox control while also performing an action requiring a QueuedTask. When access the SelectedItems on the ListBox, I get an error about the ListBox being access outside of the thread that created it.
What are the best ways to get around this? Should I just save the SelectedItems to a List before entering the QueuedTask, or is there a way to access Form controls while in the QueuedTask??
QueuedTask.Run(() =>
{
Map map = MapView.Active.Map;
foreach (string layerName in lstLayers.SelectedItems)
{
FeatureLayer currentLayer = map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name.IndexOf(layerName, StringComparison.CurrentCultureIgnoreCase) >= 0).FirstOrDefault();
currentLayer.ClearSelection();
}
}
);