Last active
December 31, 2019 12:11
-
-
Save amitkhare/a8736273f743ca8db596f455486150ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 already passed | |
} | |
this.timer = new System.Threading.Timer(x => | |
{ | |
this.SomeMethodRunsAt1600(); | |
}, null, timeToGo, Timeout.InfiniteTimeSpan); | |
} | |
private void SomeMethodRunsAt1600() | |
{ | |
//this runs at 16:00:00 | |
} | |
// usage | |
var timed = SetUpTimer(new TimeSpan(23, 45, 00)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment