How to close AddIn automatically when ArcGIS Pro is closed?

263
1
Jump to solution
11-27-2023 02:53 AM
nadja_swiss_parks
Occasional Contributor II

I coded a dockpane as an addin. a button clicked opens the dockpane. 

when I click the x on the top-right corner, the dockpane is closed. when I close ArcGIS Pro after closing the dockpane using the x, the dockpane remains closed on starting ArcGIS Pro the next time. that's great.

I'd like to implement this as a function. meaning that some listener realises, that ArcGIS Pro is getting closed and closes the dockpane too. the dockpane remains closed when I open ArcGIS Pro again, but can be activated again using the button.

How can I implement such a listener, that checks if ArcGIS Pro gets closed?  

Tags (2)
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

I am trying to catch project closing event in dock pane code:

        /// <summary>
        /// Override to implement custom initialization code for this dockpane
        /// </summary>
        /// <returns></returns>
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            ProjectClosingEvent.Subscribe(OnProjectClosing);
        }

And on project closing execute code below:

        private Task OnProjectClosing(ProjectClosingEventArgs args)
        {
            // if already cancelled, ignore
            if (args.Cancel)
                return Task.CompletedTask;

            var vm = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
            if (vm != null) vm.Hide();

            return Task.CompletedTask;
        }
 
 

View solution in original post

1 Reply
GKmieliauskas
Esri Regular Contributor

Hi,

I am trying to catch project closing event in dock pane code:

        /// <summary>
        /// Override to implement custom initialization code for this dockpane
        /// </summary>
        /// <returns></returns>
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            ProjectClosingEvent.Subscribe(OnProjectClosing);
        }

And on project closing execute code below:

        private Task OnProjectClosing(ProjectClosingEventArgs args)
        {
            // if already cancelled, ignore
            if (args.Cancel)
                return Task.CompletedTask;

            var vm = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
            if (vm != null) vm.Hide();

            return Task.CompletedTask;
        }