ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Framework.Events Namespace / ApplicationClosingEvent Class
Members Example

In This Topic
    ApplicationClosingEvent Class
    In This Topic
    Occurs when the the application is attempting to shutdown and can be handled to cancel the closure.
    Object Model
    ApplicationClosingEvent ClassSubscriptionToken ClassSubscriptionToken Class
    Syntax
    Public NotInheritable Class ApplicationClosingEvent 
       Inherits ArcGIS.Core.Events.AsyncPresentationEvent(Of CancelEventArgs)
    public sealed class ApplicationClosingEvent : ArcGIS.Core.Events.AsyncPresentationEvent<CancelEventArgs> 
    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;
      }
        );
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Core.Events.EventBase
          ArcGIS.Core.Events.AsyncPresentationEvent<TPayload>
             ArcGIS.Desktop.Framework.Events.ApplicationClosingEvent

    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also