.net - C#: How to start a thread at a specific time -


this question has answer here:

how can start background thread @ specific time of day, 16:00?

so when apps starts thread wait until time. if app starts after time thread run straight away

threadpool.queueuserworkitem(methodtorunat1600);

you can set timer @ 16:00. i've answered similar question here. should sure.

private system.threading.timer timer; private void setuptimer(timespan alerttime) {      datetime current = datetime.now;      timespan timetogo = alerttime - current.timeofday;      if (timetogo < timespan.zero)      {         return;//time passed      }      this.timer = new system.threading.timer(x =>      {          this.somemethodrunsat1600();      }, null, timetogo, timeout.infinitetimespan); }  private void somemethodrunsat1600() {     //this runs @ 16:00:00 } 

then set using

setuptimer(new timespan(16, 00, 00)); 

edit: keep reference of timer it's subject garbage collection irrespective of timer active or not.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -