Link to home
Start Free TrialLog in
Avatar of jaxrpc
jaxrpc

asked on

Add elaspedEvent to System.timer

Hi, i have created a Dim myTimer as new System.timer(1000) .

Now i have a function which i wants the timer to call every 1sec. How do i write the code for tell the timer which function to call when there's an elapsedEvent.

Assumming

Dim myTimer as New System.timer(1000) ' my timer created at run-time

Public Sub mySubProc()
'Do some stuffs here every 1 sec
End Sub

thanks
Avatar of ZeonFlash
ZeonFlash

First you have to start the timer, such as with a button click:

Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
     myTimer.Enabled = True
End Sub

Then you have to catch the Timer tick event:

Private Sub myTimer_Tick(sender As Object, e As System.EventArgs) Handles myTimer.Tick
   mySubProc()
End Sub
Avatar of jaxrpc

ASKER

hmm what if i want to do it programmatically, like adding delegate event programmatically.

like initialise a new system.timer()
and when it starts it will call an event.

And i might need to initalise an array of timers.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial