I use to set WithEvents
variables to Nothing
in Destuctor
, because this will "Remove" all the Handlers associated with Handles
keyword. Will this have the same effect for derivated classes?
Class A
Protected WithEvents _Foo as Button
Private Sub _Foo_Click Handles _Foo.Click
' ... some Click action '
End Sub
Public Sub Dispose(disposing as Boo开发者_开发百科lean)
If disposing then _Foo = Nothing ' remove handler _Foo_Click '
End Sub
End Class
Class B
Inherits A
Private Sub _Foo_Move Handles _Foo.Move
' ... some Move action '
End Sub
' ????? will or NOT remove OR handler _Foo_Move the base Dispose??'
Public Overrides Sub Dispose(disposing as Boolean)
'If disposing then _Foo = Nothing '
MyBase.Dispose(disposing)
End Sub
End Class
PS. For more clarity, suppose that _Foo
button comes from exterior and lives more that the A
class.
Yes. The _Foo = Nothing
statement in the derivated class will change the base class' protected local _Foo
to nothing, thus removing all event handlers.
精彩评论