ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Framework.Contracts Namespace / Module Class / CanUnload Method
Example

In This Topic
    CanUnload Method
    In This Topic
    When overridden in a derived class, a Module can return that it can't be unloaded.
    Syntax
    Protected Friend Overridable Function CanUnload() As Boolean
    protected internal virtual bool CanUnload()
    Remarks
    If the Framework makes the determination that a Module should be unloaded, it will first call CanUnload to verify with the Module that it is okay to do so.
    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