AnsweredAssumed Answered

Start listening to editor events when extension is enabled.  vb.net addin

Question asked by purplecruz on Aug 5, 2016
Latest reply on Aug 11, 2016 by purplecruz

I have been struggling with getting two types of addins to work together for some time now.  I have created an editor extension addin and have been able to listen to events on start editing with success.  I also have created a regular (desktop) extension and can check it on and off with success.  What I am having trouble with is that I would like the editor event listener to only work when the extension in ArcMap is enabled (checked).  I am working with the desktop extension addin now but whenever I add the event handlers to start listening when the extension is enabled it causes ArcMap to crash.  Any ideas or sample code would be greatly appreciated!  The handlers are commented out since that is what is causing ArcMap to crash.

Imports ESRI.ArcGIS.Editor
Public Class MyEditListener
    Inherits ESRI.ArcGIS.Desktop.AddIns.Extension
    Public Sub New()
    End Sub
    Protected Overrides Sub OnStartup()
        ' TODO: Uncomment to start listening to document events
        'WireDocumentEvents()
    End Sub
    Private m_editorEvent As IEditEvents_Event
    Protected Overrides Function OnSetState(ByVal state As ESRI.ArcGIS.Desktop.AddIns.ExtensionState) As Boolean
        Me.State = state
        If state = ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled Then
            MsgBox("Enabled")
            'AddHandler m_editorEvent.OnStartEditing, AddressOf Events_OnStartEditing
            'AddHandler m_editorEvent.OnStopEditing, AddressOf Events_OnStopEditing
        Else
            MsgBox("Not Enabled")
        End If
        Return MyBase.OnSetState(state)
    End Function
    Private Sub Events_OnStartEditing()
        MsgBox("start editing")
    End Sub
    Private Sub Events_OnStopEditing()
        MsgBox("stop editing")
    End Sub

Outcomes