Hello everyone,
protected override void OnClick()
{
Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"\\dep-gisdev\tidelandsdata\tlprod\Tidelands_Publication.gdb")));
Table table = fileGeodatabase.OpenDataset<Table>("Composite_Table");
}
I'm having trouble with C# code for ArcGIS Pro which will add a Table stored on a local Geodatabase in the Table of Contents for ArcGIS Pro. i was able to create some part of the code, but i'm getting an Exception Unhanded Error from Visual Studio stating : ArcGIS.Core.ConstructedOnWrongThreadException: 'This object must be created within the lambda passed to QueuedTask.Run, or on a compatible Sta thread'. I'm using a simple button to execute this code OnClick.
Solved! Go to Solution.
Hi Manny,
The short answer is that you need to call geodatabase routines from a special thread using the QueuedTask class. Your code will look like something like this:
await QueuedTask.Run( () =>
{
Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"\\dep-gisdev\tidelandsdata\tlprod\Tidelands_Publication.gdb")));
Table table = fileGeodatabase.OpenDataset<Table>("Composite_Table");
});
More details on the Pro threading model can be found in the topic Working with Multithreading in ArcGIS Pro.
Some other comments:
IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
tableFactory.CreateStandaloneTable(table, MapView.Active.Map);
Again, this needs to be wrapped inside a call to QueuedTask.Run().
I hope this helps,
--Rich
Hi Manny,
The short answer is that you need to call geodatabase routines from a special thread using the QueuedTask class. Your code will look like something like this:
await QueuedTask.Run( () =>
{
Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"\\dep-gisdev\tidelandsdata\tlprod\Tidelands_Publication.gdb")));
Table table = fileGeodatabase.OpenDataset<Table>("Composite_Table");
});
More details on the Pro threading model can be found in the topic Working with Multithreading in ArcGIS Pro.
Some other comments:
IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
tableFactory.CreateStandaloneTable(table, MapView.Active.Map);
Again, this needs to be wrapped inside a call to QueuedTask.Run().
I hope this helps,
--Rich
Thank You Rich,
i greatly appreciate your help, along with the proper resources. i was able to change the code to perform the function i needed using your code.
using System;
using System.Collections.Generic;
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.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 AddTable
{
internal class Button1 : Button
{
protected override async void OnClick()
{
await QueuedTask.Run(() =>
{
Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"\\dep-gisdev\tidelandsdata\tlprod\Tidelands_Publication.gdb")));
Table table = fileGeodatabase.OpenDataset<Table>("TL_Activities");
IStandaloneTableFactory tableFactory = StandaloneTableFactory.Instance;
tableFactory.CreateStandaloneTable(table, MapView.Active.Map);
});
}
}
}