void Distributer() { while (!this.CancellationRequested) { if (channels == null || channels.Count <= 0) { Thread.Sleep(150); continue; } Notification notification = null; lock (this.queuedNotifications) { if (this.queuedNotifications.Count > 0) { notification = queuedNotifications.Dequeue(); } } if (notification == null) { //No notifications in queue, sleep a bit! Thread.Sleep(150); continue; } PushChannelBase channelOn = null; //Get the channel with the smallest queue if (channels.Count == 1) { channelOn = channels[0]; } else { channelOn = (from c in channels orderby c.QueuedNotificationCount select c).FirstOrDefault(); } if (channelOn != null) { //Measure when the message entered the queue notification.EnqueuedTimestamp = DateTime.UtcNow; channelOn.QueueNotification(notification); PendingNotificationsToProcess--; } } }
void Distributer() { while (!this.cancelTokenSource.IsCancellationRequested) { if (channels == null || channels.Count <= 0) { Thread.Sleep(250); continue; } Notification notification = null; if (!queuedNotifications.TryDequeue(out notification)) { //No notifications in queue, sleep a bit! Thread.Sleep(250); continue; } PushChannelBase channelOn = null; //Get the channel with the smallest queue if (channels.Count == 1) { channelOn = channels[0]; } else { channelOn = (from c in channels orderby c.QueuedNotificationCount select c).FirstOrDefault(); } if (channelOn != null) { //Measure when the message entered the queue notification.EnqueuedTimestamp = DateTime.UtcNow; channelOn.QueueNotification(notification); } } }