ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Framework.Events Namespace / ApplicationClosingEvent Class / Unsubscribe Method / Unsubscribe(Func<CancelEventArgs,Task>) Method
The method being called.
Example

In This Topic
    Unsubscribe(Func<CancelEventArgs,Task>) Method
    In This Topic
    Stop being notified when the event occurs.
    Syntax
    Public Overloads Shared Sub Unsubscribe( _
       ByVal action As Func(Of CancelEventArgs,Task) _
    ) 
    public static void Unsubscribe( 
       Func<CancelEventArgs,Task> action
    )

    Parameters

    action
    The method being called.
    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