VB.NET NullReferenceException Timer.Start ()

0

I miss the following error, and I do not understand the reason ...

I have changed the access to Public of all timers in case that was the problem and nothing ...

'Block timers
Private Sub blocktimers()
    Dim i As Integer
    For Each c As Timer In Me.components.Components
        If TypeOf c Is Timer Then
            If c.Enabled And c.Interval <> 210 Then
                carray(i) = c
                ReDim Preserve carray(i + 1)
                c.Stop()
            End If
        End If
    Next
End Sub

'Release timers
Private Sub releasetimers()
    For Each c As Timer In carray
        c.Start()
    Next
End Sub

Reviewing point to point, I have seen that at some point it detects c with the value Nothing.

I've added an If c IsNot Nothing Then, before c.Start ()

Now the error does not jump and the application does not get stuck but if I put a break point in each sub, I see that releasetimers () only activates 1 timer, the value of the second timer it finds is nothing and leaves the sub, while blocktimers () is stopping more than 10 timers ...

Greetings and thank you very much!

    
asked by Adrian Hernando Solanas 27.05.2018 в 20:42
source

0 answers