我将 arcobjects 地图事件连接到 vb.net 表单以侦听地图选择更改。这一切正常,但用户在打开表单时偶尔会报告此错误。我看不到任何重现错误的模式,而且它似乎是随机的。
“无法使用已与其底层 RCW 分离的 COM 对象”
它源自我挂钩事件的表单Load()方法。
谁能帮我理解我做错了什么?我正在取消 FormClosing() 事件中的地图选择事件,我认为这是正确的方法。
Public Class MyForm
Private _activeViewEvents As IActiveViewEvents_Event
Private Sub FormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_activeViewEvents = TryCast(pMxDoc.ActiveView.FocusMap, IActiveViewEvents_Event)
AddHandler _activeViewEvents.SelectionChanged, AddressOf SelectionChanged
End Sub
Private Sub SelectionChanged
'do something when selection is changed
End Sub
Private Sub FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
RemoveHandler _activeViewEvents.SelectionChanged, AddressOf SelectionChanged
End Sub
End Class