Reputation: 9080
Is there any way to set a reminder by Day of the week? For example if I want a reminder every Friday at 10am.
What is the best way to accomplish this task?
I think I've been over thinking some sort of hours calculation. I'm hoping there is a more simplistic way of doing what I'm looking to do.
Update:
My question is more about how to figure out how to set the reminder for a specific day even if it isn't today. So lets say today is Wednesday and I want to set a reminder for every Friday (or ANY day of the week)... How would I accomplish that?
Upvotes: 1
Views: 684
Reputation: 5325
Since the reminder needs a DateTime its pretty easy. Each application has a max of 50 reminders:
DateTime dateTime = DateTime.Now; //First Friday at 10am
for (int i = 0; i < 50; i++)
{
Reminder reminder = new Reminder("MyReminder")
reminder.Content = "Reminder";
reminder.BeginTime = dateTime.AddDays(i * 7);
ScheduledActionService.Add(reminder);
}
-or this may work-
Reminder reminder = new Reminder("MyReminder")
reminder.Content = "Reminder";
reminder.BeginTime = DateTime.Now; //First Friday at 10am
reminder.Content = "Reminder";
reminder.ExpirationTime = DateTime.Now.AddDays(52 * 7);
reminder.RecurrenceType = RecurrenceInterval.Weekly;
ScheduledActionService.Add(reminder);
This is how you get the next day of week
private DateTime GetNextDay(string dayOfWeek)
{
for (int i = 0; i < 7; i++)
{
DateTime currentDateTime = DateTime.Now.AddDays(i);
if (dayOfWeek.Equals(currentDateTime.ToString("dddd")))
return currentDateTime;
}
return DateTime.Now;
}
Upvotes: 3