Example #1
0
        public void CancelTask(TimeSlicedTask task)
        {
            for (int i = 0; i < tasks_queue.Count; ++i)
            {
                if (tasks_queue.At(i) == task)
                {
                    tasks_queue.RemoveAt(i);

                    break;
                }
            }
        }
Example #2
0
        private void UpdateTasks()
        {
            timer.Restart();

            bool finish = false;

            while (!finish)
            {
                if (tasks_queue.Count > 0)
                {
                    TimeSlicedTask curr_task = tasks_queue.At(0);

                    if (!curr_task.Running)
                    {
                        curr_task.Start();
                    }

                    curr_task.Update();

                    if (curr_task.Finished)
                    {
                        for (int y = 0; y < tasks_queue.Count; ++y)
                        {
                            if (tasks_queue.At(y) == curr_task)
                            {
                                tasks_queue.RemoveAt(y);

                                break;
                            }
                        }
                    }
                }
                else
                {
                    finish = true;
                }

                if (timer.ReadTime().Milliseconds > max_time_per_frame.Milliseconds)
                {
                    finish = true;
                }
            }
        }
Example #3
0
        public void PushTask(TimeSlicedTask task, int priority = 0)
        {
            if (task != null)
            {
                bool already_added = false;

                for (int i = 0; i < tasks_queue.Count; ++i)
                {
                    if (tasks_queue.At(i) == task)
                    {
                        already_added = true;

                        break;
                    }
                }

                if (!already_added)
                {
                    tasks_queue.Add(task, priority);
                }
            }
        }