Esempio n. 1
0
        public void Cycle()
        {
            if (ItemsRunning < _appSettings.MaxBackgroundJobs)
            {
                var inQueueJobs = ItemsQueue.Where(x => x.Status == QueueStatus.InQueue);

                while (ItemsQueue.Where(x => x.Status == QueueStatus.InQueue).Count() > 0 && ItemsRunning < _appSettings.MaxBackgroundJobs)
                {
                    var nextJob = ItemsQueue.Where(x => x.Status == QueueStatus.InQueue).FirstOrDefault();

                    if (nextJob != null)
                    {
                        nextJob.Status = QueueStatus.InProgress;
                        QueueItemStatusChange.Invoke(nextJob);
                        StartItem(nextJob);
                    }
                }
            }
        }
Esempio n. 2
0
        public void ItemDone(Task <bool> task, QueueItem queueItem)
        {
            ItemsRunning--;

            if (queueItem.Status != QueueStatus.Aborted)
            {
                if (task.Result == false)
                {
                    queueItem.Status = QueueStatus.Failed;
                }
                else
                {
                    queueItem.Status = QueueStatus.Complete;
                }

                // Fire event when item done
                QueueItemStatusChange.Invoke(queueItem);
            }

            // Execute a cycle
            Cycle();
        }
Esempio n. 3
0
 internal void SetQueueItemStatusChange(EntryItem queueItemEntry, EntryItem.State state)
 {
     QueueItemStatusChange?.Invoke(queueItemEntry, state);
 }