I would like to have an event triggered in my app which runs continuously during the day at a certain time, say at 4:00pm. I thought about running the timer every second and when the time is equal to 4:00pm run the event. That works. But I’m wondering if there’s a way to just get the callback once at 4:00pm and not having to keep checking.
Share
How about something like this, using the
System.Threading.Timerclass?Note that if you use a
System.Threading.Timer, the callback specified byTimerCallbackwill be executed on a thread pool (non-UI) thread—so if you’re planning on doing something with your UI at 4:00, you’ll have to marshal the code appropriately (e.g., usingControl.Invokein a Windows Forms app, orDispatcher.Invokein a WPF app).