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

ApplicationClosingEvent Class
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 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

internal class Module1 : Module
{

  // Called by Framework when ArcGIS Pro is closing
  protected override bool CanUnload()
  {
    //return false to ~cancel~ Application close
    return false;
  }

  internal class Module2 : Module
  {
    public Module2()
    {
      ArcGIS.Desktop.Framework.Events.ApplicationClosingEvent.Subscribe(OnApplicationClosing);
    }
    ~Module2()
    {
      ArcGIS.Desktop.Framework.Events.ApplicationClosingEvent.Unsubscribe(OnApplicationClosing);
    }

    private Task OnApplicationClosing(System.ComponentModel.CancelEventArgs args)
    {
      args.Cancel = true;
      return Task.FromResult(0);
    }

    // cref: ARCGIS.DESKTOP.CORE.EVENTS.PROJECTOPENEDEVENT
    // cref: ARCGIS.DESKTOP.CORE.EVENTS.PROJECTOPENEDEVENT.SUBSCRIBE
    // cref: ARCGIS.DESKTOP.CORE.EVENTS.PROJECTOPENEDEVENT.UNSUBSCRIBE
    // cref: ARCGIS.DESKTOP.FRAMEWORK.CONTRACTS.MODULE.INITIALIZE
    // cref: ARCGIS.DESKTOP.FRAMEWORK.CONTRACTS.MODULE.UNINITIALIZE
    #region How to determine when a project is opened
    protected override bool Initialize() //Called when the Module is initialized.
    {
      ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to Project opened event
      return base.Initialize();
    }

    private void OnProjectOpened(ProjectEventArgs obj) //Project Opened event handler
    {
      MessageBox.Show($"{Project.Current} has opened"); //show your message box
    }

    protected override void Uninitialize() //unsubscribe to the project opened event
    {
      ProjectOpenedEvent.Unsubscribe(OnProjectOpened); //unsubscribe
      return;
    }
Inheritance Hierarchy

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

Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also