ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Framework.Contracts Namespace / Module Class / Initialize Method
Example

In This Topic
    Initialize Method (Module)
    In This Topic
    When overridden in a derived class, gives the custom Module a chance to initialize itself and return its status to the calling Framework.
    Syntax
    protected internal virtual bool Initialize()
    Protected Friend Overridable Function Initialize() As Boolean
    Remarks

    A custom Module has two opportunities to initialize itself: its class constructor and its Initialize method. The Framework calls both functions whenever a Module is loaded. Modules load either explicitly with FrameworkApplication.FindModule or implicitly whenever any of their DAML elements (Panes, DockPanes, Controls, etc) are loaded. For example, when a DockPane or a Button on a Ribbon Tab is created, their parent module will automatically load if it hasn't already done so.

    The Initialize method has the added benefit of returning whether the initialization was successful or not. If initialization fails, the Framework immediately calls Uninitialize.

    Example
    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