public void Add (Task task) { if (task == null) return; if (task.Source == null) throw new Exception ("Attempting to add Task with no source!"); Task old_task = null; lock (big_lock) { // Keep track of when immediate priority tasks are // added so that we can throttle if the scheduler // is being slammed with them. if (task.Priority == Priority.Immediate) { // Shift our times down by one Array.Copy (last_immediate_times, 1, last_immediate_times, 0, immediate_throttle_count - 1); last_immediate_times [immediate_throttle_count - 1] = DateTime.Now; } old_task = tasks_by_tag [task.Tag] as Task; task.Schedule (this); // Re-adding the same task is basically a no-op --- we // just update the timestamp and return. if (old_task == task) return; if (Debug) { Logger.Log.Debug ("Adding task {0}", task.Tag); if (task.Description != null) Logger.Log.Debug (" Desc: {0}", task.Description); } if (task.Priority == Priority.Shutdown) shutdown_task_queue.Enqueue (task); else tasks_by_tag [task.Tag] = task; Monitor.Pulse (big_lock); } // If we clobbered another task, call cancel on it. // This happens after we release the lock, since // cancellation could result in a task group post-hook // being run. if (old_task != null) old_task.Cancel (); }