问题
I've been trying to design support for recurring events (like you would see in Outlook, or a task manager, etc). I've been doing a lot of digging on Google and StackOverflow, but not much luck.
Wondering if anyone has any pointers or resources.
'Requirements'
- Support for daily events (occurring Mon, Tues, Thurs at 10am or every 15 mins)
- Monthly events
Anything more is a bonus but those would be the minimum.
Thanks!
回答1:
What I've used for this is the built in TaskScheduler. There's an easy to use wrapper for it here: http://taskscheduler.codeplex.com/
If you haven't already, search Task Scheduler in the start menu and play with it. That wrapper essentially lets you programmatically do everything you can with the GUI.
回答2:
Take a look at Quartz .NET:
http://quartznet.sourceforge.net/features.html
回答3:
The answer that Bob gave for this question is a pretty good one. He based his solution on the SQL Server team's work on sysschedules.
http://technet.microsoft.com/en-us/library/ms178644.aspx.
回答4:
Check iCal Wiki and iCal RFC (especially sections on "Duration" and "Recurrence Rule"). I think it will provide you some good starting point on how to represent such events.
Excerpt from the RFC:
... For example "the last work day of the month" could be represented as:
FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1
回答5:
If the problem that you are trying to solve is that you can only respond to such events when your program is running, that is true. The most practical solution to this problem is to run you program in the background, most often with a notification icon on the taskbar.
If the problem is that you are unsure how to track such events, you can either use an existing framework (see roken's answer), set timers (research System.Threading.Timer), or periodically compare DateTime.Now against various DateTime objects. With the latter two, you will need to serialize DateTime objects to save them to the disk between sessions.
来源:https://stackoverflow.com/questions/9137473/c-sharp-recurring-event-like-for-a-calendar