timer - Best way to schedule tasks in vb.net -
i need execute commandline on hour , half past hour. there better ways this? maybe ones don't involve checking hour every second.
timer 1 second interval:
private sub timer1_tick(byval sender system.object, byval e system.eventargs) handles timer1.tick          integer = 0 24             if timestring = & ":00:00" & or timestring = "0" & & ":00:00 or if timestring = & "30:00:" & or timestring = "0" & & ":30:00              end if         next end sub      
step 1 - calculate time next hour or half hour mark;
step 2 - set timer's elapsed period equal time calculated in step 1;
step 3 - when timer ticks, reset elapsed time 30 minutes , work need do.
if process has run on hour / half hour recalculate time needed in step3 rather setting 30 minutes (this compensate drifting).
here code calculate milliseconds midnight; should able work there
private function millisecondstomidnight() integer      dim returnvalue integer     dim ts timespan      dim tomorrow datetime = today.adddays(1)     ts = tomorrow.subtract(now)      returnvalue = ts.totalmilliseconds()      ts = nothing     return returnvalue  end function      
Comments
Post a Comment