I am trying to run a query on a FeatureLayer in the Active Map through a button in a ProWindow, but either the code throws a Thread Exception if I try to perform a Search on the Layer outside of an async/await block or it skips over the code inside the await portion.
Here is the code I have and I have tried it with and without the async/await code:
private async void Locate_Click(object sender, RoutedEventArgs e)
{
String layerName = "Search PLUS Cases";
var fLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(l => l.Name.Equals(layerName));
if (fLayer != null)
{
if (this.TbxPLUSCase.Text != null && this.TbxPLUSCase.Text != "")
{
Dictionary<long, string> RoadDict = new Dictionary<long, string>();
string whereClause = "CASE_ID = '" + this.TbxPLUSCase.Text.ToUpper() + "'";
QueryFilter qf = new QueryFilter();
qf.WhereClause = whereClause;
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
using (ArcGIS.Core.Data.Table PLUSTable = fLayer.GetTable())
{
using (RowCursor rowCursor = PLUSTable.Search(qf))
{
while (rowCursor.MoveNext())
{
using (ArcGIS.Core.Data.Row row = rowCursor.Current)
{
string dictvalue = row["CASE_ID"].ToString();
long v = Convert.ToInt64(row["objectid"].ToString());
RoadDict[v] = dictvalue;
};
}
}
}
});
}
}
this.Close();
}