Exemplo n.º 1
0
        /// <summary>
        /// Mainthread
        /// </summary>
        private void DoWork()
        {
            Stack <SchedulerTask> toRemove = new Stack <SchedulerTask>();

            while (running)
            {
                if (taskQueue.Count > 0)
                {
                    SchedulerTask t;
                    while (!taskQueue.TryDequeue(out t))
                    {
                        Thread.Sleep(TickDelay);
                    }
                    if (t.GetType() == typeof(DelayedSchedulerTask) || t.GetType() == typeof(RepeatingSchedulerTask))
                    {
                        RepeatingSchedulerTask dst = (RepeatingSchedulerTask)t;
                        dst.Tick();
                        if (!dst.Remove)
                        {
                            repeatingTasks.Add(dst);
                        }
                    }
                    else
                    {
                        t.Run();
                    }
                }

                foreach (RepeatingSchedulerTask task in this.repeatingTasks)
                {
                    task.Tick();
                    if (task.Remove)
                    {
                        toRemove.Push(task);
                    }
                }

                while (toRemove.Count > 0)
                {
                    repeatingTasks.Remove((RepeatingSchedulerTask)toRemove.Pop());
                }

                Thread.Sleep(TickDelay);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a repeating task to the list
 /// </summary>
 /// <param name="task">Task to be executed</param>
 public void PushRepeatingTask(RepeatingSchedulerTask task)
 {
     taskQueue.Enqueue(task);
 }