I'm executing this code:
private Task ExecuteAddFieldTool(string fieldName, string fieldAlias, string fieldType, int? fieldLength=null, bool isNullable=true)
{
var inTable = DeltaLayer.Name;
var workspaceName = ((IInternalMapMember) DeltaLayer).WorkspaceName;
var parameters = Geoprocessing.MakeValueArray(inTable, fieldName, fieldType.ToUpper(), null, null,
fieldLength, fieldAlias, isNullable ? "NULABLE" : "NON_NULLABLE");
var env = Geoprocessing.MakeEnvironmentArray(workspace: workspaceName);
var cts = new System.Threading.CancellationTokenSource();
var results = Geoprocessing.ExecuteToolAsync("management.AddField",
parameters, env, cts.Token, (eventName, o) =>
{
switch (eventName)
{
case "OnValidate":
if (((IGPMessage[]) o).Any(it => it.Type == GPMessageType.Warning))
{
MessageBox.Show($"{eventName}: {o}");
}
break;
case "OnMessage":
case "OnProgressMessage":
MessageBox.Show($"{eventName}: {o}");
//if ((string)o == "Updating...") ...
break;
case "OnProgressPos":
MessageBox.Show($"{eventName}: {o} %");
});
return results;
}The code execute fine, and the field is created, but after the last message shown - "Updating..." the UI freezes and have to crash ArcGis Pro from Task Manager.
I can see the field created only after restarting the project in ArcGis Pro.
I have tries all kind of variation on QueuedTask, Task, Task Factory, async and await with no success!