Hello,
I am trying to use AddHandler to designate an array of timers to call a function when they have elapsed.
Below is my code:
Unfortunately, when the AddHandler line is called, it instantly fires the cd_Tick function (which I do not want to happen until the timer has elapsed), then never fires it again. Does anyone know why this would be happening?
I am trying to use AddHandler to designate an array of timers to call a function when they have elapsed.
Below is my code:
VB.NET:
Public Shared Sub CreateCooldown(ByVal name As String, ByVal duration As Integer, ByVal timetype As String)
cooldowns(a).Name = name
cooldowns(a).Timer = New Timers.Timer
With cooldowns(a).Timer
.Enabled = True
.Interval = 5000 ' An arbitrary value for this example
End With
AddHandler cooldowns(a).Timer.Elapsed, cd_Tick(cooldowns(a).Name)
cooldowns(a).Timer.Start()
ReDim Preserve cooldowns(cooldowns.Length)
End Sub
Public Shared Function cd_Tick(ByVal name As String)
' Do stuff here
Return Nothing
End Function
Unfortunately, when the AddHandler line is called, it instantly fires the cd_Tick function (which I do not want to happen until the timer has elapsed), then never fires it again. Does anyone know why this would be happening?
Last edited: