ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / Callback Method / Callback(Action<IEditContext>,Dataset) Method
The function object.
The dataset to operate on.
Example

In This Topic
    Callback(Action<IEditContext>,Dataset) Method
    In This Topic
    Registers that the edit operation will callback into the given function in the context of an edit operation. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Sub Callback( _
       ByVal action As Action(Of EditOperation.IEditContext), _
       ByVal dataset As Dataset _
    ) 

    Parameters

    action
    The function object.
    dataset
    The dataset to operate on.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Read and Write blob fields with a row cursor in a callback
    QueuedTask.Run(() =>
    {
      var editOp = new EditOperation();
      editOp.Name = "Blob Cursor";
      var featLayer = MapView.Active.Map.FindLayers("Hydrant").First() as FeatureLayer;
    
      editOp.Callback((context) =>
      {
        using (var rc = featLayer.GetTable().Search(null, false))
        {
          while (rc.MoveNext())
          {
            using (var record = rc.Current)
            {
              //read the blob field and save to a file
              var msw = new MemoryStream();
              msw = record["BlobField"] as MemoryStream;
              using (FileStream file = new FileStream(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write))
              {
                msw.WriteTo(file);
              }
    
              //read file into memory stream
              var msr = new MemoryStream();
              using (FileStream file = new FileStream(@"d:\images\Hydrant.jpg", FileMode.Open, FileAccess.Read))
              {
                file.CopyTo(msr);
              }
    
              //put the memory stream in the blob field and save to feature
              record["BlobField"] = msr;
              record.Store();
    
            }
          }
        }
      }, featLayer.GetTable());
      if (!editOp.IsEmpty)
      {
        var result = editOp.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
    });
    Creating a Row
    public async Task CreatingARow()
    {
      string message = String.Empty;
      bool creationResult = false;
      EditOperation editOperation = new EditOperation();
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
    
        using (Geodatabase geodatabase = new Geodatabase(
          new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
    
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          //declare the callback here. We are not executing it .yet.
          editOperation.Callback(context =>
          {
            TableDefinition tableDefinition = enterpriseTable.GetDefinition();
            int assetNameIndex = tableDefinition.FindField("ASSETNA");
    
            using (RowBuffer rowBuffer = enterpriseTable.CreateRowBuffer())
            {
              // Either the field index or the field name can be used in the indexer.
              rowBuffer[assetNameIndex] = "wMain";
              rowBuffer["COST"] = 700;
              rowBuffer["ACTION"] = "Open Cut";
    
              // subtype value for "Abandon".
              rowBuffer[tableDefinition.GetSubtypeField()] = 3;
    
              using (Row row = enterpriseTable.CreateRow(rowBuffer))
              {
                // To Indicate that the attribute table has to be updated.
                context.Invalidate(row);
              }
            }
          }, enterpriseTable);
    
          try
          {
            creationResult = editOperation.Execute();
            if (!creationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also