I want to create a background worker for a WinForm that triggers code whenever midnight rolls by.
I have an idea of how to do it, but I’m pretty sure it’s not the best way to do it.
while(1==1)
{
//if Datetime.Now == midnight, execute code
//sleep(1second)
}
Use a
System.Timers.Timerand at application start up just calculate the difference betweenDateTime.NowandDateTime.Today.AddDays(0). Then set the interval for that amount.I actually did something just like this recently:
AND:
Usage:
DayChangedNotifier.DayChanged += ....