0

due to some VS problems I have started declaring timers at runtime such as

Private WithEvents _TmrAll As New Timer

Now when I shutdown my app, I want to disable all timers. I used to make it like so:

Private Sub pDisableAllTimers()

    For Each T As Control In Me.Controls
        Dim sName As String = T.GetType.Name
        If sName = "Timer" Then
            T.Enabled = False
        End If
    Next T
End Sub

But for the timers declared at runtime, this doesn't seem to work. At least they're not found in the loop.

Thank you.

tmighty
  • 8,222
  • 19
  • 78
  • 182

1 Answers1

0

If you want to do this at runtime, you'll need to create the components container (If needed) and add your timer(s). For more information check out this

   If components Is Nothing Then
        components = New System.ComponentModel.Container()
   End If       
   components.Add(_TmrAll)

and then code pDisableAllTimers as follows:

Private Sub pDisableAllTimers()

    For Each T As Component In components.Components
        Dim sName As String = T.GetType.Name
        If sName = "Timer" Then
            CType(T, Timer).Enabled = False
        End If
    Next T

End Sub
Community
  • 1
  • 1
Jim Hewitt
  • 1,632
  • 4
  • 25
  • 26