ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Framework.Events Namespace / ApplicationClosingEvent Class / Unsubscribe Method / Unsubscribe(SubscriptionToken) Method
The registration token.
Example

In This Topic
    Unsubscribe(SubscriptionToken) Method
    In This Topic
    Stop being notified when the event occurs.
    Syntax
    public static void Unsubscribe( 
       SubscriptionToken token
    )
    Public Overloads Shared Sub Unsubscribe( _
       ByVal token As SubscriptionToken _
    ) 

    Parameters

    token
    The registration token.
    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;
        }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also