This is a once-daily scenario description.
If you really want to avoid creating a service, you can start the timer at intervals of 1 minute. Every time a timer delegate is called, you need to run something like this (pseudocode):
lastInvokeDay = LoadLastInvokeDate(); If (lastInvokeDay < DateTime.Now.Date && timeOfDayToRun == DateTime.Now.Time) { try { today = DateTime.Now.Date; runMyTask(); } catch.. finally { lastInvokeDay = today; SaveLastInvokeDay(lastInvokeDay); } }
Keep in mind that lastInvokeDay must be stored either in the database or in a file ...
Now, if you want to enable immediate task invocation, you can simply call runMyTask() on demand. If it is important for you that runMyTask happens more than once a day, you could create a synchronized block of code inside it (with the lock instruction) and transfer the lastInvokeDay check inside.
Does this answer your question?
Uri abramson
source share