This got me curious so I wrote a small console application to visualize what happens if you do this experiment using a timer:
Private WithEvents _t As New Timers.Timer With {.Enabled = True}
Private Sub _t_Elapsed(sender As Object, e As Timers.ElapsedEventArgs) Handles _t.Elapsed
Console.WriteLine("tick")
End Sub
Sub Main()
' let it tick for 5 seconds
Task.Delay(5000).Wait()
' destroy the current timer
Console.WriteLine("destroying this timer")
_t.Dispose()
_t = Nothing
' add a little pause
Task.Delay(1000).Wait()
' create a new timer
Console.WriteLine("creating a new timer")
_t = New Timers.Timer With {.Enabled = True}
' let it tick for 5 seconds
Task.Delay(5000).Wait()
End Sub
If you run this code, you will find that it does indeed attach the event handler when the instance of _t
is replaced. I don't know how it does that, but the magic probably lies in the Handles
keyword. Anyhow, the answer is yes.