Friday, July 08, 2005

A small (programming) victory

After much puzzlement, I finally found (and fixed) the cause of an abominable bug that has something to do with .NET, garbage collection, and ArcObjects. Basically I wanted to get the ArcMap “Editor” object, which gives me access to the feature-created and feature-deleted events:

Editor editor = (Editor)application.FindExtensionByName("ESRI Object Editor");

But the event handlers that I added to it weren’t getting called – I would create a feature, and get no event. Only after some careful experimentation did I discover that the problem disappeared when I assigned the Editor to a static variable (class variable). It’s almost as if the Editor object gets garbage collected, thereby losing all the event handlers you added to it. Needless to say, I am now pinning it down with a static variable!

2 Comments:

At 1/08/2006 7:23 p.m., Anonymous Anonymous said...

I had the same problem and it wouldn't go away. I tried your idea of making the editor variable static and the problem went away.

Thanks heaps, it was really bugging me. No pun intended.

 
At 1/08/2006 10:08 p.m., Blogger Jonathan said...

Yeah right, you did intend those puns :-) Glad it helped!

 

Post a Comment

<< Home