I am designing a small ArcObjects (10.3.1) .Net Desktop Application that analyzes an .mxd for sde layers with broken connections and if possible fixes them. Everything works fine, however when retrieving the first Map
from the MapDocument
class via _pMapDocument.get_Map(i)
it can be incredibly slow (where _pMapDocument
is my MapDocumentClass
object).
In trying to problem solve this I used the advice on the ArcObjects documentation page here, for initializing the ActiveView
before working the the Map
object.
When opening or creating a map document with the IMapDocument Open() or New() methods, you should always make subsequent calls to IActiveView::Activate() in order to properly initialize the display of the PageLayout and Map objects.
I found that if I call _pMapDocument.ActiveView.Activate(0)
before retrieving the Map
this call also can be incredibly slow but the subsequent call _pMapDocument.get_Map(i)
is very fast.
Is it possible to retrieve the Map
object in a faster way? And/or is there a way to identify a MapDocument
that may take a long time to access its Map
so that I can avoid hanging up my program? I have also tried circumventing the Map object as I just want to get the layers with _pMapDocument.Layer[i, j]
but this also takes quite sometime on the first call. Many of the .mxds I am trying to fix are quite old, e.g. created from previous ArcMap versions 10.1, 10.2, etc., and I am wondering if this is an issue. Additionally I am a bit worried that the thing I am trying to fix, broken sde layers, is what is slowing down the retrieving of the map as perhaps when the map is opening it is continually looking for sde connections that no longer exist.
A more complete code snippet is listed below:
using ESRI.ArcGIS.Carto;
_pMapDocument.Open(sFilePath);
for (int i = 0; i < _pMapDocument.MapCount; i++)
{
var pMap = _pMapDocument.get_Map(i);
ILayer pLayer;
for (int j = 0; j < pMap.LayerCount; j++)
{
pLayer = GetLayers(pMap.Layer[j], _dtLayers, ref j);
}
}