Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trigger a timer 1

Status
Not open for further replies.

tvbruwae

Programmer
Aug 9, 2001
224
EU
Hi

I have implemented a timer in VB .NET so that a piece of code is executed at regular intervals. This works fine, apart from the fact that the code is not executed until the first interval has elapsed. As this interval is quite large (several hours) it means that the code is not executed within the first hours after the application is started..

This is the code:

Code:
Dim MyTimer As New System.Timers.Timer()
AddHandler MyTimer.Elapsed, AddressOf TimerMethod
MyTimer.Interval = 43200000
MyTimer.Start()

Can I manually trigger the "TimerMethod" procedure once before starting the timer?
 
Sure...just before the MyTimer.Start, execute TimerMethod(parameters if necessary)

Code:
Dim MyTimer As New System.Timers.Timer()
AddHandler MyTimer.Elapsed, AddressOf TimerMethod
MyTimer.Interval = 43200000
TimerMethod()
MyTimer.Start()

I tend to use this in my services applications, because my timer internals tend to be large as well.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Actually the parameters are a problem as I would not know what to send with the procedure call.. This is how the TimerMethod is defined:

Code:
Public Sub TimerMethod(ByVal source As Object, ByVal e As ElapsedEventArgs)
 
Try:

TimerMethod(Nothing, Nothing)


=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
Never thought it would be so simple.. Thanks for the tip!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top