Exemple #1
0
        protected void Run()
        {
            while (!_finished)
            {
                //
                // Find out the next closest event in the sorted list.
                //
                BrunetTask task = null;
                bool       fire = false;
                if (_task_queue.First == null)
                {
                    task = (BrunetTask)_in_queue.Dequeue();
                }
                else
                {
                    _now_ticks = DateTime.UtcNow.Ticks;
                    LinkedListNode <BrunetTask> next_node = _task_queue.First;
                    if (next_node.Value.Instant > _now_ticks)
                    {
                        int milliseconds = (int)((next_node.Value.Instant - _now_ticks) / 10000.0);
                        if (milliseconds < 0)
                        {
                            Environment.Exit(1);
                        }
                        //Console.WriteLine("millis:{0}", milliseconds);
                        task = (BrunetTask)_in_queue.Dequeue(milliseconds,
                                                             out fire);
                    }
                    else
                    {
                        fire = true;
                    }
                }

                if (fire)
                {
                    //
                    // Time to fire the next event in the queue.
                    //

                    task = _task_queue.First.Value;
                    _task_queue.RemoveFirst();
                    //Console.WriteLine("Firing event");
                    task.Fire();
                }
                else
                {
                    //
                    // Add the new task to the sorted list.
                    //
                    if (task != null)
                    {
                        AddTask(task);
                    }
                }
            }
        }
Exemple #2
0
        protected void AddTask(BrunetTask task)
        {
            //
            // Classical linked list insertion.
            //
            LinkedListNode <BrunetTask> current = _task_queue.Last;

            while (current != null)
            {
                if (task.Instant > current.Value.Instant)
                {
                    _task_queue.AddAfter(current, task);
                    break;
                }
                current = current.Previous;
            }

            if (current == null)
            {
                _task_queue.AddFirst(task);
            }
        }
Exemple #3
0
 public void Schedule(BrunetTask task)
 {
     _in_queue.Enqueue(task);
 }
Exemple #4
0
 public void Schedule(BrunetTask task) {
   _in_queue.Enqueue(task);
 }
Exemple #5
0
    protected void AddTask(BrunetTask task) {
      //
      // Classical linked list insertion.
      // 
      LinkedListNode<BrunetTask> current = _task_queue.Last;
      while (current != null) {
	if (task.Instant > current.Value.Instant) {
	  _task_queue.AddAfter(current, task);
	  break;
	}
	current = current.Previous;
      }

      if (current == null) {
	_task_queue.AddFirst(task);
      }
    }