internal Status UpdateIndex() { UpdateJob proposedJob = Storage.CreateUpdateJob(ViewsInGroup().Select(x => x.Storage)); UpdateJob nextJob = null; var updateQueue = _UpdateQueueFactory.ListForGroup(GroupName()); updateQueue.Lock(); try { if (updateQueue.Count > 0) { nextJob = updateQueue.FirstOrDefault(x => x.Equals(proposedJob)); if (nextJob == null) { QueueUpdate(proposedJob); nextJob = proposedJob; } } else { QueueUpdate(proposedJob); nextJob = proposedJob; nextJob.Run(); } } finally { updateQueue.Unlock(); } nextJob.Wait(); return(nextJob.Result); }
private UpdateJob QueueUpdate(UpdateJob job) { job.Finished += (sender, e) => { UpdateJob nextJob; _updateQueue.TryDequeue(out nextJob); if (_updateQueue.TryPeek(out nextJob)) { nextJob.Run(); } }; _updateQueue.Enqueue(job); if (_updateQueue.Count == 1) { job.Run(); } return(job); }