Select to view content in your preferred language

ArcMap hangs on shutdown when debugging a .NET add-in

2191
4
Jump to solution
08-28-2014 01:25 PM
JonathanBailey
Frequent Contributor

I'm developing an ArcMap add-in using .NET and Visual Studio 2012. I've set the debugging option for the project to start ArcMap. Ordinarily, when I shut down ArcMap, I'm returned to Visual Studio and debugging stops.

EXCEPT when I open this one particular document in ArcMap. Then, I'm returned to Visual Studio, but the debugging process doesn't stop. The ArcMap process is still running and consuming about 50% CPU (on a 4 core machine).

If I run ArcMap by itself with the compiled add-in, ArcMap shuts down normally.

It almost seems like I'm hanging on to an unmanaged resource somewhere, but I created another map document that has content that causes the same objects to be created, and ArcMap shuts down normally and returns me to Visual Studio when I open this document.

I've also found that, when this occurs, the Dispose() method is not called on my add-in button.

Any idea why this is happening?

0 Kudos
1 Solution

Accepted Solutions
JonathanBailey
Frequent Contributor

Agreed. This lead me to investigate whether the map document itself was a problem, since it didn't seem to happen with other map documents. I ran the map document through the MXD Doctor, and, problem solved.

View solution in original post

0 Kudos
4 Replies
JonathanBailey
Frequent Contributor

Sol Wuensch‌,

I commented out the code so that it does literally nothing:

using ESRI.ArcGIS.Carto;

using ESRI.ArcGIS.Display;

namespace SpatialBridge.Addresses.ArcMapAddIn

{

    public sealed class FishboneCommand : ESRI.ArcGIS.Desktop.AddIns.Button

    {

        public FishboneCommand()

        {

        }

        protected override void OnClick()

        {

        }

        protected override void OnUpdate()

        {

        }

        private void Events_ActiveViewChanged()

        {

        }

        private void OnActiveViewEventsAfterDraw(IDisplay display, esriViewDrawPhase drawPhase)

        {

        }

    }

}

And the behaviour persists. Also, code analysis didn't find anything.

Thanks,

Jon.

0 Kudos
RollinNelson1
Deactivated User

Jonathon:

The only thing I would suggest is to use ReleaseComObject(if applicable).

In my case I created a geoprocessor in my .NET code. Then, my code kept hanging at "shutdown" after it ran successfully. Once I made the change, the execution was smooth and no hang-ups.

//Create geoprocessor

IGeoProcessor2 arankaGP = new GeoProcessorClass();

.

.

.

Marshal.ReleaseComObject(arankaGP);

0 Kudos
OwenEarley
Frequent Contributor

This is often the cause of these kind of problems. However, it seems odd that the problem persists with the ESRI.ArcGIS.Desktop.AddIns.Button boilerplate code and no user code.

JonathanBailey
Frequent Contributor

Agreed. This lead me to investigate whether the map document itself was a problem, since it didn't seem to happen with other map documents. I ran the map document through the MXD Doctor, and, problem solved.

0 Kudos