Hello Everybody,
I am working on add-in for ArcGIS Pro 3.1, the code is in C#.
The tool acesses data in Oracle database, create a QueryTable that I want to display in a WPF DataGrid Control.
I use snippet from ProSnippets Geodatabase to get QueryTable, which works, but I don't know how to open the table in the WPF DataGrid.
I get an error:
System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
I use QueuedTask.Run to open the QueryTable, but it is probably in a different Thread. How to access QueryTable from WPF?
Here is my code:
public partial class Window1 : Window
{
private async void clsBtn_Click(object sender, RoutedEventArgs e)
{
//open Query Table
var t = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
using (Geodatabase sdedb01 = new Geodatabase(Module1.connectionProperties2))
{
QueryDef queryDef = Module1.GetQueryDef();
QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
{
Name = "wellsView",
PrimaryKeys = sdedb01.GetSQLSyntax().QualifyColumnName("DAT_GDO_GF.GEO_PROFIL", "KLIC_GDO") + ", " +
sdedb01.GetSQLSyntax().QualifyColumnName("DAT_GDO_GF.GEO_PROFIL", "KLIC_GEO") + ", " +
sdedb01.GetSQLSyntax().QualifyColumnName("DAT_GDO_GF.GEO_HOR", "POR_HOR")
};
ArcGIS.Core.Data.Table tbl = sdedb01.OpenQueryTable(queryTableDescription);
//here the QueryTable works:
MessageBox.Show("Number of rows in querytable je: " + Convert.ToString(tbl.GetCount()));
return tbl;
}
});
//ERROR, System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it
dataGrid1.DataContext = t;
}
Thanks for any help!
Lenka