Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
How do I call a function every x minutes in VB.NET? Please provide a code sample if possible.

Thanks....
Posted

Hi,

Try:
VB
Dim minutes As Integer = 5   ' change 5 into the count of minutes
Dim t As New System.Timers.Timer(60000 * minutes)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start() ' start the timer
VB
Private Sub t_Elapsed(sender As Object, e As System.Timers.ElapsedEventArgs)
	' this method will be called every 5 minutes
End Sub

Hope this helps.
 
Share this answer
 
v3
Comments
komaliks 25-Jun-13 3:21am    
At the line t.Elapsed += New System.Timers.ElapsedEventHandler(t_Elapsed), i got a compilation error. "Public event Elapsed(sender As Object, e As System.Timers.ElapsedEventArgs) is an event and cannot be called directly.use a RaiseEvent statement to raise an event
Thomas Daniels 25-Jun-13 3:23am    
I updated my answer.
Just Googling for[^] you may find many many tutorials on using timers with VB.NET.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900