Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class ElapseManager
- Public Shared ReadOnly TicksPerMillisecond As Long = Stopwatch.Frequency / 1000
- Private ReadOnly ElapseCollection As New Dictionary(Of String, Elapser)
- Public Function ChangeInterval(ByVal Name As String, ByVal Ticks As Long) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- ElapseCollection(Name).Interval = Ticks
- Return True
- End If
- Return False
- End Function
- Public Function ChangeInterval(ByVal Name As String, ByVal Milliseconds As Double) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- ElapseCollection(Name).Interval = Milliseconds * TicksPerMillisecond
- Return True
- End If
- Return False
- End Function
- Public Function Check(ByVal Name As String) As Boolean
- If ElapseCollection.ContainsKey(Name) Then Return ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp
- Return False
- End Function
- Public Function Check(ByVal Name As String, ByVal Ticks As Long, Optional ByVal TriggerOnFirstCheck As Boolean = True) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- Return ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp
- Else
- If Ticks > 0 Then
- Dim nextTime As Long = Stopwatch.GetTimestamp + Ticks
- ElapseCollection.Add(Name, New Elapser(nextTime, Ticks))
- Return If(TriggerOnFirstCheck, True, ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp)
- Else
- Throw New Exception("Ticks must be greater than 0" & vbCrLf & vbTab & " - TizzyT")
- End If
- End If
- End Function
- Public Function Check(ByVal Name As String, ByVal Milliseconds As Double, Optional ByVal TriggerOnFirstCheck As Boolean = True) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- Return ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp
- Else
- If Milliseconds > 0 Then
- Dim newTicks As Long = Milliseconds * TicksPerMillisecond
- Dim nextTime As Long = Stopwatch.GetTimestamp + newTicks
- ElapseCollection.Add(Name, New Elapser(nextTime, newTicks))
- Return If(TriggerOnFirstCheck, True, ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp)
- Else
- Throw New Exception("Milliseconds must be greater than 0" & vbCrLf & vbTab & " - TizzyT")
- End If
- End If
- End Function
- Public Function CheckRestart(ByVal Name As String) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- Dim Elapsed As Boolean = ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp
- ElapseCollection(Name).NextTime = Stopwatch.GetTimestamp + ElapseCollection(Name).Interval
- Return Elapsed
- End If
- Return False
- End Function
- Public Function CheckRestart(ByVal Name As String, ByVal Ticks As Long, Optional ByVal TriggerOnFirstCheck As Boolean = True) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- Dim Elapsed As Boolean = ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp
- If Elapsed Then ElapseCollection(Name).NextTime = Stopwatch.GetTimestamp + ElapseCollection(Name).Interval
- Return Elapsed
- Else
- If Ticks > 0 Then
- Dim nextTime As Long = Stopwatch.GetTimestamp + Ticks
- ElapseCollection.Add(Name, New Elapser(nextTime, Ticks))
- Return If(TriggerOnFirstCheck, True, ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp)
- Else
- Throw New Exception("Ticks must be greater than 0" & vbCrLf & vbTab & " - TizzyT")
- End If
- End If
- End Function
- Public Function CheckRestart(ByVal Name As String, ByVal Milliseconds As Double, Optional ByVal TriggerOnFirstCheck As Boolean = True) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- Dim Elapsed As Boolean = ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp
- If Elapsed Then ElapseCollection(Name).NextTime = Stopwatch.GetTimestamp + ElapseCollection(Name).Interval
- Return Elapsed
- Else
- If Milliseconds > 0.0 Then
- Dim newTicks As Long = Milliseconds * TicksPerMillisecond
- Dim nextTime As Long = Stopwatch.GetTimestamp + newTicks
- ElapseCollection.Add(Name, New Elapser(nextTime, newTicks))
- Return If(TriggerOnFirstCheck, True, ElapseCollection(Name).NextTime < Stopwatch.GetTimestamp)
- Else
- Throw New Exception("Milliseconds must be greater than 0" & vbCrLf & vbTab & " - TizzyT")
- End If
- End If
- End Function
- Public Function Remove(ByVal Name As String) As Boolean
- Return ElapseCollection.Remove(Name)
- End Function
- Public Function Restart(ByVal Name As String) As Boolean
- If ElapseCollection.ContainsKey(Name) Then
- ElapseCollection(Name).NextTime = Stopwatch.GetTimestamp + ElapseCollection(Name).Interval
- Return True
- End If
- Return False
- End Function
- Private Class Elapser
- Public NextTime As Long
- Public Interval As Long
- Sub New(ByVal NextTime As Long, ByVal Interval As Long)
- Me.NextTime = NextTime
- Me.Interval = Interval
- End Sub
- End Class
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement