public IWoopsaNotifications WaitNotification(TimeSpan timeout, int lastNotificationId) { WoopsaServerNotifications result = new WoopsaServerNotifications(); _watchClientActivity.Restart(); if (lastNotificationId != IdResetLostNotification) { if (!_notificationsLost) { _lastRemovedNotificationId = _pendingNotifications.RemoveOlder(_lastRemovedNotificationId, lastNotificationId); // Wait notifications if none is available if (_pendingNotifications.Count == 0) { _waitNotificationEvent.Reset(); WaitHandle.WaitAny(new WaitHandle[] { _waitStopEvent, _waitNotificationEvent }, timeout); } // prepare result with all available notifications without dequeueing result.AddRange(_pendingNotifications.PeekNotifications(WoopsaSubscriptionServiceConst.MaxGroupedNotificationCount)); } else { throw new WoopsaNotificationsLostException("Notifications have been lost because the queue was full. Acknowledge the error by calling WaitNotification with LastNotificationId = 0"); } } else { _notificationsLost = false; // Wait notifications if none is available if (_pendingNotifications.Count == 0) { _waitNotificationEvent.Reset(); WaitHandle.WaitAny(new WaitHandle[] { _waitStopEvent, _waitNotificationEvent }, timeout); } // prepare result with all available notifications without dequeueing result.AddRange(_pendingNotifications.PeekNotifications(WoopsaSubscriptionServiceConst.MaxGroupedNotificationCount)); } _watchClientActivity.Restart(); return(result); }
public IWoopsaNotifications WaitNotification(TimeSpan timeout, int lastNotificationId) { WoopsaServerNotifications result = new WoopsaServerNotifications(); _watchClientActivity.Restart(); if (lastNotificationId != IdResetLostNotification) { if (!_notificationsLost) { _lastRemovedNotificationId = _pendingNotifications.RemoveOlder(_lastRemovedNotificationId, lastNotificationId); // Wait notifications if none is available if (_pendingNotifications.Count == 0) { _waitNotificationEvent.Reset(); WaitHandle.WaitAny(new WaitHandle[] { _waitStopEvent, _waitNotificationEvent }, timeout); } // prepare result with all available notifications without dequeueing result.AddRange(_pendingNotifications.PeekNotifications(WoopsaSubscriptionServiceConst.MaxGroupedNotificationCount)); } else throw new WoopsaNotificationsLostException("Notifications have been lost because the queue was full. Acknowledge the error by calling WaitNotification with LastNotificationId = 0"); } else { _notificationsLost = false; // Wait notifications if none is available if (_pendingNotifications.Count == 0) { _waitNotificationEvent.Reset(); WaitHandle.WaitAny(new WaitHandle[] { _waitStopEvent, _waitNotificationEvent }, timeout); } // prepare result with all available notifications without dequeueing result.AddRange(_pendingNotifications.PeekNotifications(WoopsaSubscriptionServiceConst.MaxGroupedNotificationCount)); } _watchClientActivity.Restart(); return result; }