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;
}