Beispiel #1
0
        public async Task RunScheduleAsync(TParam param, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (IsDirty)
            {
                _graph = new SchedulerGraph <T>(Tasks, Rules);
            }

            cancellationToken.ThrowIfCancellationRequested();

            var graphCopy = new SchedulerGraph <T>(_graph);
            var graphLock = new SemaphoreSlim(1);

            await Task.WhenAll(graphCopy.GetPendingTasks().Select(x => RunTask(x, param, graphCopy, graphLock, cancellationToken)));
        }
Beispiel #2
0
        private void UpdateSchedule()
        {
            _schedule.Clear();
            _schedule.Capacity = Tasks.Count;

            var graph = new SchedulerGraph <T>(Tasks, Rules);

            var pendingTasks = new Queue <int>(graph.GetPendingTasks());

            while (pendingTasks.Count > 0)
            {
                int currentTask = pendingTasks.Dequeue();

                _schedule.Add(Tasks[currentTask]);

                foreach (int nextTask in graph.GetNextTasks(currentTask))
                {
                    pendingTasks.Enqueue(nextTask);
                }
            }

            IsDirty = false;
        }