vb.net - Run function each day at set time -
so have app need run email function each day @ time set. in case set 6pm. left running , went home work. @ 6pm received email function ran. come midnight ran again, , because ran @ midnight , that's technically today, won't run again until 6pm next day instead of 6pm tonight since ran @ midnight. can't figure out what's wrong , why ran @ midnight.
private target datetime private state maintenancestate = maintenancestate.waitingtostart public maintenancetime new timespan(hour, min, 0) private waitinginterval new timespan(0, 5, 0) ' 5 minutes private enum maintenancestate waitingtostart started end enum private sub tmr_maintenance_tick(sender object, e eventargs) handles tmr_maintenance.tick dim ts timespan = target.subtract(datetime.now) lblstatus.text = ts.tostring("hh\:mm\:ss") if datetime.now >= target tmr_maintenance.stop() select case state case maintenancestate.waitingtostart sendemail() state = maintenancestate.started target = datetime.now.add(waitinginterval) case maintenancestate.started if done = 1 target = datetime.now.add(waitinginterval) else state = maintenancestate.waitingtostart target = getnextmaintenancetarget(maintenancetime) end if end select tmr_maintenance.start() end if end sub private function getnextmaintenancetarget(byval time timespan) datetime dim dt datetime = datetime.today.add(time) if datetime.now > dt dt = dt.adddays(1) end if return dt end function
i suggest removing code scheduling , instead schedule executable run using task scheduler.
Comments
Post a Comment