Select to view content in your preferred language

GP ExecuteAsync locks layer

166
2
a month ago
zhangjinzhou
Emerging Contributor

I am creating layers and attributes using Geoprocessing.ExecuteToolAsync. The workflow is as follows:

  1. Create an empty layer with "management.CreateFeatureClass".
  2. Create multiple fields using "management.AddField" in a loop.

The Problem:

In the loop, after the first field is created, the second and subsequent fields cannot be added. The error message is: "Table is being edited."

Additional Information:

If I create the layer without adding any fields and then try to delete the table manually in the Pro UI, I encounter the same error.

Below is a sample of my usage of Geoprocessing.ExecuteToolAsync:

            var args = Geoprocessing.MakeValueArray(dataset, fieldName, fieldType.ToUpper(), null, null,
                   fieldLength, fieldAlias, isNullable ? "NULABLE" : "NON_NULLABLE");
            System.Threading.CancellationTokenSource _cts = new System.Threading.CancellationTokenSource();
            var results = await Geoprocessing.ExecuteToolAsync("management.AddField", args, null, _cts.Token,
                (eventName, o) =>
                {
                    switch (eventName)
                    {
                        case "OnValidate":
                            if (((IGPMessage[])o).Any(it => it.Type == GPMessageType.Warning))
                            {
                                _cts.Cancel();
                            }
                            break;
                        case "OnMessage":
                        case "OnProgressMessage":
                            IGPMessage[] gpMsgs = o as IGPMessage[];
                            if (gpMsgs != null)
                            {
                                // Check for any renamed warning messages.  If there is one, get the new field name 
                                // from it.
                                foreach (IGPMessage gpMsg in gpMsgs.Where(i => i.Type == GPMessageType.Warning))
                                {

                                    Match renamedMsg = Regex.Match(gpMsg.Text, renameWarningPattern);
                                    if (renamedMsg != null)
                                    {
                                        string[] words = renamedMsg.Value.Split(' ');
                                        if (words.Length > 0)
                                        {
                                            // The last word is the new field name; strip off anything that isn't a 'word' character (e.g. strip off
                                            // any trailing '...'.  
                                            Match wordMatch = Regex.Match(words.Last(), @"(\w*)");
                                            if (wordMatch != null)
                                                newFldName = wordMatch.Value;
                                        }
                                    }
                                }
                            }
                            break;
                        case "OnProgressPos":
                            //  MessageBox.Show($"{eventName}: {o} %");
                            break;
                        default:
                            //   MessageBox.Show($"{eventName}: {o} %");
                            break;
                    }
                }, GPExecuteToolFlags.None);
            if (results.IsFailed)
                return "";
            else
                return newFldName;

 

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

 You can use management.AddFields to add all fields in one call.  

UmaHarano
Esri Regular Contributor

The Pro SDK also provides a .NET API that allows you to create new feature classes with fields.
https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-DDL

0 Kudos