editEvents.OnChangeFeature -= new IEditEvents_OnChangeFeatureEventHandler(OnChangeFeature);
Solved! Go to Solution.
public class EditorExtension1 : ESRI.ArcGIS.Desktop.AddIns.Extension { private IEditEvents_Event _editEvents; private int i = 0; public EditorExtension1() { } protected override void OnStartup() { IEditor theEditor = ArcMap.Editor; _editEvents = theEditor as IEditEvents_Event; _editEvents.OnChangeFeature += new IEditEvents_OnChangeFeatureEventHandler(_editEvents_OnChangeFeature); } void _editEvents_OnChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj) { IFeature feature = obj as IFeature; feature.set_Value(feature.Fields.FindField("point_x"), (i = i + 1)); }
Hello,I have an OnChangeFeature event wired to fire whenever a feature is changed (obviously). Within the event, I am updating a field value, which then fires the event again. Hence, infinite loop. How can I prevent this from happening?This is an application logic issue. Are there no other options for you to not attempt a field update within that event?Can you explain your use case for needing to do this in the event?
This is an application logic issue. Are there no other options for you to not attempt a field update within that event?Can you explain your use case for needing to do this in the event?
public class EditorExtension1 : ESRI.ArcGIS.Desktop.AddIns.Extension { private IEditEvents_Event _editEvents; private int i = 0; public EditorExtension1() { } protected override void OnStartup() { IEditor theEditor = ArcMap.Editor; _editEvents = theEditor as IEditEvents_Event; _editEvents.OnChangeFeature += new IEditEvents_OnChangeFeatureEventHandler(_editEvents_OnChangeFeature); } void _editEvents_OnChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj) { IFeature feature = obj as IFeature; feature.set_Value(feature.Fields.FindField("point_x"), (i = i + 1)); }
Make sure you're not calling IFeature.Store in the event as this will re-fire the behavior. Its called internally once the event is complete.public class EditorExtension1 : ESRI.ArcGIS.Desktop.AddIns.Extension { private IEditEvents_Event _editEvents; private int i = 0; public EditorExtension1() { } protected override void OnStartup() { IEditor theEditor = ArcMap.Editor; _editEvents = theEditor as IEditEvents_Event; _editEvents.OnChangeFeature += new IEditEvents_OnChangeFeatureEventHandler(_editEvents_OnChangeFeature); } void _editEvents_OnChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj) { IFeature feature = obj as IFeature; feature.set_Value(feature.Fields.FindField("point_x"), (i = i + 1)); }