AddHandler to array of Timers

Hi there,

I have an array of timers instantiated in code, say manyTimers(25) - now I would love to add a eventhandler to all those, calling the same method. I could Imagine to add the handlers by

[code]dim i as integer

for i = 0 to manyTimers.ubound // Loop through the timers
AddHandler manyTimers(i).Action, AddressOf ManyTimerAction // Add Handler
next

[/code]

How do I know which timer fired in the method?

The Method looks as follows ATM:

Sub ManyTimerAction(sender as Timer)
//Do Something
End Sub

Or is there a better way to do this?

That’s the right way
The timer you get passed is the one the action is being called for

But is there any way to figure out which index this timer has in the array?

manyTimers.indexOf(sender) will return the index.

Great! Thanks!

You’re welcome!

Personally I’d suggest your code be written in a way that its not relevant what the index is
Thats an implementation detail that could change when you revise code & then if it depends on the index your code breaks in funny ways

But its just a suggestion

Thank you !!