Call Method from Instantiated Timer outside Session

I’m tracking down some bugs in my WebProject.

All this project does is process POSTs received.
The open event opens a database connection.
A heartbeat method inserts a record in a database.

I think, I would like to instantiate a Timer (i.e. not a WebTimer) via code so it always runs and have that timer run the heartbeat method periodically.

This is how I started but I don’t know how to make it call the method or put the code into the timers ‘run’ event.

Var myTimer As New Timer
myTimer.Enabled = True
myTimer.Period = 5000
myTimer.RunMode = Timer.RunModes.Multiple

// – how to call myMethod?

Add the WebTimer as a Property instead. Configure and Run it in the App Open Event.

Maybe instantiating it is not the problem. I can also move it to a property but I still have this issue.
The main question is how do I run code when it fires? It does not have the characteristics I’m familiar with using the normal Timers on the shelf. i.e. it doesn’t have a ‘Run’ event for me to key in code.

Sounds like you might be looking for

1 Like

Thank you both.
I read that document and tried some of it before even posting. However the dot autocomplete did not list ‘.Action’ as an option so I incorrectly assumed that it wasn’t available and tried other entries. Thanks for the help. final code…

// -------------------------------------------
// – App property
// -------------------------------------------
db_heartbeat As Timer

// -------------------------------------------
// – in the open event of the app:
// -------------------------------------------
db_heartbeat = New Timer
db_heartbeat.Enabled = True
db_heartbeat.Period = 5000
db_heartbeat.RunMode = Timer.RunModes.Multiple

// – ‘.Action’ has to be typed manually but it does work in version 2020r2.1
AddHandler db_heartbeat.Action, AddressOf myMethod
// --------------------------------------------------
// – method
// – parameter: sender As Timer
// --------------------------------------------------
myMethod (sender As Timer)
// – put your code in this method