Skip to main content
A newer version of this page is available. .

How to: Create Hourly Recurrence

  • 2 minutes to read
public AppointmentItem CreateAppointmentPattern(string subj, int categoryId) {
    AppointmentItem apt = new AppointmentItem(AppointmentType.Pattern);
    apt.Start = DateTime.Today.AddHours(9);
    apt.End = apt.Start.AddMinutes(5);
    apt.Subject = subj;
    apt.LabelId = categoryId;
    return apt;
}
    // An appointment is set every 3 hours. Five occurrences.
    AppointmentItem apt1 = CreateAppointmentPattern("Every 3 hours. Five occurrences.", 1);
    apt1.RecurrenceInfo.Type = RecurrenceType.Hourly;
    apt1.RecurrenceInfo.Start = apt1.Start;
    apt1.RecurrenceInfo.Periodicity = 3;
    apt1.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount;
    apt1.RecurrenceInfo.OccurrenceCount = 5;
    scheduler.AppointmentItems.Add(apt1);

    // An appointment is set every 5 hours. Infinite (no end date).
    AppointmentItem apt2 = CreateAppointmentPattern("Every 5 hours. Infinite (no end date).", 1);
    apt2.RecurrenceInfo.Type = RecurrenceType.Hourly;
    apt2.RecurrenceInfo.Start = apt2.Start;
    apt2.RecurrenceInfo.Periodicity = 5;
    apt2.RecurrenceInfo.Range = RecurrenceRange.NoEndDate;
    scheduler.AppointmentItems.Add(apt2);

    // An appointment is set every hour. Appointment series duration is 24 hours.
    AppointmentItem apt3 = CreateAppointmentPattern("Every hour.  Series duration is 24 hours.", 1);
    apt3.RecurrenceInfo.Type = RecurrenceType.Hourly;
    apt3.RecurrenceInfo.Start = apt3.Start;
    apt3.RecurrenceInfo.Periodicity = 1;
    apt3.RecurrenceInfo.Range = RecurrenceRange.EndByDate;
    apt3.RecurrenceInfo.End = apt3.RecurrenceInfo.Start.AddHours(24);
    scheduler.AppointmentItems.Add(apt3);