Terminating a GP tool while running (in VB.Net)

Discussion created by justin_damic on Aug 9, 2013
Latest reply on Sep 8, 2013 by justin_damic
I have a UI that has a button that exports currently selected vector features to a KML using the LayerToKML Geoprocessor.  Whilst it works great on locally stored featureclasses there are certain featureclasses (eg statewide cadastre) on our greater network that are way too big (and our WAN network is very slow!!), and hence take forever to process, even if just a few features are selected for export.   While part of my code does a quick check to see how many features exist in the dataset before executing the GP, and gives a warning that it may take until the end of time itself to complete, I want to allow the user to terminate the LayerToKML process should they find them selves onto their second cup of coffee while it is running.  Currently if my form is closed whilst this GP is running the whole ArcGIS drops out and all is lost.

Is this possible to do programatically?

This is my GP sub

Private Sub KMZGenerator(pfeaturelayer As IFeatureLayer, LayerName As String, FolderPath As String)

        ' Initialize the geoprocessor.
        Dim GP As Geoprocessor = New Geoprocessor()
        'Calculates current date and time and provides as a string
        Dim rightNow As DateTime = DateTime.Now
        Dim strCurrentDateTimeString As String
        strCurrentDateTimeString = rightNow.ToString("ddd_dd_MMM_yyyy_hh_mm_sstt")

        'Creates KMZ
        Dim LayerToKMLTool As ESRI.ArcGIS.ConversionTools.LayerToKML = New ESRI.ArcGIS.ConversionTools.LayerToKML()
        GP.SetEnvironmentValue("workspace", FolderPath)
        LayerToKMLTool.layer = pfeaturelayer
        LayerToKMLTool.layer_output_scale = 1
        LayerToKMLTool.out_kmz_file = LayerName & "_" & strCurrentDateTimeString & ".kmz"

        GP.Execute(LayerToKMLTool, Nothing)

    End Sub

Thnx Justin