ArcGIS Pro 2.7 API Reference Guide
GPToolExecuteEventHandler Delegate
ExampleExample 

ArcGIS.Desktop.Core.Geoprocessing Namespace : GPToolExecuteEventHandler Delegate
The event name values are:
Message object. Use following type conversion - see code example below.
Callback delegate, pass a lambda call to ExecuteToolAsync(String,IEnumerable<String>,IEnumerable<KeyValuePair<String,String>>,CancelableProgressor,GPExecuteToolFlags).
Syntax
public delegate void GPToolExecuteEventHandler( 
   string eventName,
   object o
)
Public Delegate Sub GPToolExecuteEventHandler( _
   ByVal eventName As String, _
   ByVal o As Object _
) 

Parameters

eventName
The event name values are:
  • "OnValidate" - triggers when internal validation is done.
  • "OnMessage"
  • "OnProgressMessage"
  • "OnProgressPos"
  • "OnBeginExecute" - triggers when execution begins.
  • "OnEndExecute" - triggers when execution is complete.
o
Message object. Use following type conversion - see code example below.
  • "OnValidate" - (o as IGPMessage[])
  • "OnMessage" - (o as IGPMessage)
  • "OnProgressMessage" - (string)o
  • "OnProgressPos" - (int)o
  • "OnBeginExecute" - o = null
  • "OnEndExecute" - (o as IGPResult)
Example
System.Threading.CancellationTokenSource _cts;

string ozone_points = @"C:\data\ca_ozone.gdb\O3_Sep06_3pm";

string[] args = { ozone_points, "OZONE", "", "in_memory\\raster", "300",
                    "EMPIRICAL", "300", "5", "5000",
                    "NBRTYPE=StandardCircular RADIUS=310833.272442914 ANGLE=0 NBR_MAX=10 SECTOR_TYPE=ONE_SECTOR",
                    "PREDICTION", "0.5", "EXCEED", "", "K_BESSEL" };

string tool_path = "ga.EmpiricalBayesianKriging";

_cts = new System.Threading.CancellationTokenSource();

var result = Geoprocessing.ExecuteToolAsync(tool_path, args, null, _cts.Token,
    (event_name, o) =>  // implement delegate and handle events
    {
        switch (event_name)
        {
            case "OnValidate": // stop execute if any warnings
                if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Warning))
                    _cts.Cancel();
                break;

            case "OnProgressMessage":
                string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o });
                System.Windows.MessageBox.Show(msg);
                _cts.Cancel();
                break;

            case "OnProgressPos":
                string msg2 = string.Format("{0}: {1} %", new object[] { event_name, (int)o });
                System.Windows.MessageBox.Show(msg2);
                _cts.Cancel();
                break;
        }
    });

var ret = await result;
_cts = null;
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

GPToolExecuteEventHandler Members
ArcGIS.Desktop.Core.Geoprocessing Namespace