AnsweredAssumed Answered

'Table panes cannot be accessed from a thread other than the thread they were created on.' Opening a standalone table pane  (ArcGIS Pro SDK C#)

Question asked by JPHILLI2_TXDOT on Jan 15, 2020
Latest reply on Jan 16, 2020 by RRuh-esristaff

Hello, I am experiencing an error when trying to add a standalone table to a map. 

 

I saw some other threads and borrowed some code from them, but I keep running into this same Error:

 

 

The code successfully routes my table (from a local gdb) and adds the routed linework and the underlying standalone table to the map.  However, when I attempt to open the table in the table pane, I keep getting this error. 

Any help would be much appreciated! 

Thanks

John

 

 

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Core.Geoprocessing;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;

namespace BulkLoadTool
{
internal class Tomato : Button
{
protected async override void OnClick()
{
try
{
var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First(l => l.Name.Contains("TxDOT_Roadways_Edits"));

//var Datapath =
await QueuedTask.Run(() =>
{
var gdbPath = lyr.GetFeatureClass().GetDatastore().GetPath();
var tblName = lyr.GetTable().GetName();
string fullPath = Path.Combine(gdbPath.LocalPath, tblName);

 

 

string in_routes = fullPath; //Datapath.Result
string route_id_field = "GID";
string gPath = Path.Combine(@"C:\TxDOT\BulkLoad\AssetTables", System.IO.File.ReadAllText(@"C:\TxDOT\BulkLoad\LayerReference\configFiles\selGDB.log"));
string inTbl = Convert.ToString(Module1.Current.TblDropDown.SelectedItem);
string inTblPath = Path.Combine(gPath, inTbl);
string in_table = inTblPath;

string in_event_properties = "RDBD_GMTRY_LN_ID LINE ASSET_LN_BEGIN_DFO_MS ASSET_LN_END_DFO_MS";
string out_layer = Module1.Current.TblDropDown.SelectedItem.ToString();

var args = Geoprocessing.MakeValueArray(in_routes, route_id_field, in_table, in_event_properties, out_layer);
string toolPath = @"C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\Toolboxes\Linear Referencing Tools.tbx\MakeRouteEventLayer";

Geoprocessing.ExecuteToolAsync(toolPath, args);

string sGDB = System.IO.File.ReadAllText(@"C:\TxDOT\BulkLoad\LayerReference\configFiles\selGDB.log");

using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(gPath))))
{
using (Table table = geodatabase.OpenDataset<Table>(inTbl))
{
IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
var insTbl = tableFactory.CreateStandaloneTable(table, MapView.Active.Map, inTbl);
FrameworkApplication.Panes.OpenTablePane(insTbl);
//return insTbl;
}
}


});

 

}
catch (Exception e)
{
Trace.WriteLine(e.Message);
}
}

 

}

}

Outcomes