private static void NotifySubscribersOnTimeEvent() { try { _Notifying = true; _Timer.Stop(); #if DEBUG Console.WriteLine("{0} NotificationServer notifying subscribers count: {1}", DateTime.Now, _RequestList.Count); #endif // Reset next notification time... _NextEventTime = DateTime.MinValue; if (_RequestList.Count == 0) { return; } DateTime now = CalendarModel.GetCalendarDateTime(UtcNow); NotificationRequest[] requestList = new NotificationRequest[_RequestList.Count]; _RequestList.CopyTo(requestList); DateTime nextNotification = DateTime.MinValue; foreach (NotificationRequest item in requestList) { if (item.NotificationTime <= now) { if (item.NotificationHandler != null) { //if (System.Threading.Thread.CurrentThread.ManagedThreadId != item.ThreadId) //{ // //System.Threading.SendOrPostCallback callback = new System.Threading.SendOrPostCallback(SendNotification); // //System.Windows.Threading.DispatcherSynchronizationContext.Current.Post(callback, item); //} //else item.NotificationHandler(item, new NotificationServerEventArgs(now)); } _RequestList.Remove(item); } else if (item.NotificationTime < nextNotification || nextNotification == DateTime.MinValue) nextNotification = item.NotificationTime; } if (nextNotification > DateTime.MinValue) { SetNextEventTime(nextNotification); } //else // Console.WriteLine("Not setting next notification time..."); } finally { _Notifying = false; } }
public static void Unregister(NotificationRequest request) { _RequestList.Remove(request); }
public static void UpdateNotification(NotificationRequest request) { SetNextEventTime(request.NotificationTime); }
public static void Register(NotificationRequest request) { _RequestList.Add(request); SetNextEventTime(request.NotificationTime); }
private void OnStartTimeNotification(NotificationRequest request, NotificationServerEventArgs e) { if (_StartTimeAction != eStartTimeAction.None) { this.StartTimeNotificationRequest = null; ProcessStartTimeReachedActions(); } }