ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Framework.Events Namespace / ApplicationClosingEvent Class / Subscribe Method
The method to call.
Subscribe with a strong reference. Default is false (weak reference).
Example

In This Topic
    Subscribe Method (ApplicationClosingEvent)
    In This Topic
    Call the specified method whenever the event occurs.
    Syntax

    Parameters

    action
    The method to call.
    keepSubscriberAlive
    Subscribe with a strong reference. Default is false (weak reference).

    Return Value

    A SubscriptionToken that can be used to unsubscribe with.
    Example
    Prevent ArcGIS Pro from Closing
    {
      // There are two ways to prevent ArcGIS Pro from closing
      // 1. Override the CanUnload method on your add-in's module and return false.
      // 2. Subscribe to the ApplicationClosing event and cancel the event when you receive it
    
      // 1. Override the CanUnload method on your add-in's module and return false.
      // Called by Framework when ArcGIS Pro is closing
      {
        //return false to ~cancel~ Application close
      }
      {
        // 2. Subscribe to the ApplicationClosing event and cancel the event when you receive it
        // Replace this line:
        // ArcGIS.Desktop.Framework.Events.ApplicationClosingEvent.Subscribe(() => { });
    
        // With the following, which matches the required delegate signature:
        ArcGIS.Desktop.Framework.Events.ApplicationClosingEvent.Subscribe((args) =>
        {
          //Do something here, e.g. prompt user to save work
          return Task.CompletedTask;
        }
        );
    
    
        // in the Application Closing event handler set the Cancel property of the event args to true to prevent Pro from closing
      }
    }
    // Called by Framework when ArcGIS Pro is closing
    {
      ArcGIS.Desktop.Framework.Events.ApplicationClosingEvent.Subscribe((args) =>
      {
        //Do something here, e.g. prompt user to save work
        return Task.CompletedTask;
      }
        );
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also