/// <summary> /// Adds an entry to the schedule using ScheduleItem property values. /// </summary> /// <param name="name">(Optional) Name or comment describing the scheduled item. Can be searched to retrieve ScheduleItem object.</param> /// <param name="recurring">True if the ScheduleItem should recur at a stated interval.</param> /// <param name="interval">If the ScheduleItem is set to recur, the interval between scheduled events.</param> /// <param name="scheduledAt">The next (or first) date\time when the ScheduleItem reached event will fire.</param> /// <param name="onScheduleAt">The callback method to execute when the scheduledAt time is reached. This method's signature is myMethod(object sender, ScheduleItem e);</param> /// <returns>The created ScheduleItem. The Id value will be populated, since it was added to the schedule.</returns> public static ScheduleItem AddToSchedule(string name, bool recurring, TimeSpan interval, DateTime scheduledAt, OnScheduledAtDelegate onScheduleAt, object state) { ScheduleItem newItem = new ScheduleItem(name, recurring, interval, scheduledAt, onScheduleAt, state); newItem.Id = Guid.NewGuid(); scheduleList.Add(newItem); return newItem; }
private const int SchedulerDefaultTick = OneSecondInMillis * 60; // default Schedule timer resolution: 5 seconds #endif #region Methods /// <summary> /// Adds a ScheduleItem to the mfSchedule. /// </summary> /// <param name="newItem">The ScheduleItem to add to the schedule. The Id property value must be an empty GUID (Guid.Empty) value.</param> /// <returns>The created ScheduleItem. The Id value will be populated, since it was added to the schedule.</returns> public static ScheduleItem AddToSchedule(ScheduleItem newItem) { if (newItem.Id.Equals(Guid.Empty)) { newItem.Id = Guid.NewGuid(); scheduleList.Add(newItem); return newItem; } else throw new ArgumentException("ScheduleItem.Id is not empty, it has been previously added to schedule."); }
/// <summary> /// Removes the passed ScheduleItem from the schedule and releases references to the OnScheduledAt method. /// </summary> /// <param name="itemToDelete">The ScheduleItem object to be deleted from the schedule.</param> public static void DeleteFromSchedule(ScheduleItem itemToDelete) { scheduleList.Remove(itemToDelete); }
private static void OnScheduledAtReached(ScheduleItem e) { OnScheduledAtDelegate handler = e.OnScheduledAt; if (handler != null) { handler(null, e); } }