Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm having a problem when setting the IactivewViews extent. I have done it the same way on other places and it does work. In here, it just throws me a LoaderLockException.

        // OLD CODE
        private void airspaceElementsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Name.StartsWith("feature_"))
            {
                IFeatureWorkspace workspace = ((IDataset)_LoadedAirspace.UnderlyingObject.Table).Workspace as IFeatureWorkspace;
                ITable relatedTable = workspace.OpenTable(e.Node.Parent.Name);

                int oid = GetNodeObjectId(e.Node);
                IRow tempRow = relatedTable.GetRow(oid);

                IGeometry geom = null;

                if (tempRow is IFeature)
                {
                    IFeature feat = tempRow as IFeature;

                    geom = feat.ShapeCopy;
                    ISpatialReference srCopy = ((IClone)geom.SpatialReference).Clone() as ISpatialReference;

                    IEnvelope envelope = new EnvelopeClass();
                    envelope.SpatialReference = srCopy;
                    envelope.Union(geom.Envelope);
                    envelope.Expand(.25, .25, false);

                    // error here!
                    IActiveView view = ((IMxDocument)m_application.Document).ActiveView;
                    view.Extent = envelope;
                }
                else
                    return;

                Marshal.ReleaseComObject(relatedTable);
            }
            else
                return;
        }

By the way, this is inside a IDockableWindowDef. Any chance that THAT is ruining things for me?

edit following the suggestions of my fellow friends, I did on two separate statements. First I'm trying to get IMxDocument from m_application and then casting it to IActiveView.

It crashes when I'm trying to cast m_application.Document to IMxDocument (check new code below)

    private void airspaceElementsTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
    {
        if (e.Node.Name.StartsWith("feature_"))
        {
            IFeatureWorkspace workspace = ((IDataset)_LoadedAirspace.UnderlyingObject.Table).Workspace as IFeatureWorkspace;
            ITable relatedTable = workspace.OpenTable(e.Node.Parent.Name);

            int oid = GetNodeObjectId(e.Node);
            IRow tempRow = relatedTable.GetRow(oid);

            IGeometry geom = null;

            if (tempRow is IFeature)
            {
                IFeature feat = tempRow as IFeature;

                geom = feat.ShapeCopy;
                ISpatialReference srCopy = ((IClone)geom.SpatialReference).Clone() as ISpatialReference;

                IEnvelope envelope = new EnvelopeClass();
                envelope.SpatialReference = srCopy;
                envelope.Union(geom.Envelope);
                envelope.Expand(.25, .25, false);

                // crash here
                IMxDocument document = m_application.Document as IMxDocument;
                IActiveView view = document.ActiveView;
                view.Extent = envelope;
            }
            else
                return;

            Marshal.ReleaseComObject(relatedTable);
        }
        else
            return;
    }
share|improve this question
    
what happens if you cast IMxDocument.FocusMap as IActiveView? –  Kirk Kuykendall Mar 1 '11 at 14:26
2  
I would try breaking your statement into two statements to determine whether it is the cast to IMxDocument or accessing the ActiveView property that is throwing the exception. –  Adam Armour Mar 1 '11 at 16:04
    
Hey guys. I'll try both. Thanks for the help! –  George Mar 1 '11 at 16:55
    
I tried both suggestions and both failed :(. –  George Mar 1 '11 at 17:19
    
I suspect the LoaderLock exception only happens when you are within a VS debugging session? –  Petr Krebs Mar 1 '11 at 17:49

1 Answer 1

up vote 3 down vote accepted

Since your code is executing in an event handler, it may be that you are making calls to ArcObjects on a separate thread. Take a look at ESRI's documentation for writing multithreaded ArcObjects code, specifically the section Calling ArcObjects from a thread other than the main thread.

share|improve this answer
    
This could be it. I've had other problems with that before. What should it do? Just place the entire method separetly and call it from within the event? –  George Mar 1 '11 at 18:01
    
I ran a quick test (version 9.3.1) and verified that this is not the issue. Perhaps it would help to post the rest of the code for your class that implements IDockableWindowDef. –  Adam Armour Mar 1 '11 at 19:01
    
Unfortunately I can't post the rest of the code. What I can tell you is that I load all my TreeNode objects using a cursor, which later is released. My tag object (of each node is the OID) and each category holds a table name. –  George Mar 1 '11 at 19:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.