I have a timer running every second, and I plan to have a check within every tick of that timer.
I have a hashtable which has two integers, the value I am trying to set as a time. Every time the timer ticks, it will add 1 to the value of whatever it was previously.
I have tried modifying the hashtable directly in my For each statement, that errors, I also tried creating a new hash table which stores the key and the new time that it will be, and after this set the values. But this gets an Object reference not set to an instance of an object, which isn't making sense as there is a check in place to ensure that it's not null.
Code
    Private Sub expiryTimer_Tick(sender As Object, e As EventArgs) Handles expiryTimer.Tick
    Dim toRemove As List(Of Integer)
    Dim toSet As Hashtable
    'Loop through active table
    If Active IsNot Nothing Then
        For Each key In Active
            If Active(key) >= 10 Then
                toRemove.Add(0)
            Else
                toSet.Add(key, Active(key) + 1)
            End If
        Next
    End If
    'Set Values
    If toSet IsNot Nothing Then
        For Each value In toSet
            Active(value) = toSet(value)
        Next
    End If
    'Remove Values
    If toRemove IsNot Nothing Then
        For Each value In toRemove
            Active.Remove(value)
        Next
        toRemove.Clear()
    End If
End Sub
 
     
    