Created
February 17, 2016 21:44
-
-
Save WildGenie/9ae2721d6f12452e0977 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
void Main() | |
{ | |
//If the calling context is important (for example in GUI applications) | |
//you'd might want to save the Synchronization Context | |
//for example: context = SynchronizationContext.Current | |
//and use if in the lambda below e.g. s => context.Post(s => this.Close(), null) | |
var timer = new System.Threading.Timer( | |
s => this.Close(), null, CalcMsToHour(23, 00, 00), Timeout.Infinite); | |
} | |
int CalcMsToHour(int hour, int minute, int second) | |
{ | |
var now = DateTime.Now; | |
var due = new DateTime(now.Year, now.Month, now.Day, hour, minute, second); | |
if (now > due) | |
due.AddDays(1); | |
var ms = (due - now).TotalMilliseconds; | |
return (int)ms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment