/// <summary>
 /// Insert a new task
 /// </summary>
 /// <param name="task"></param>
 /// <returns></returns>
 public virtual SchedulerTask InsertTask(SchedulerTask task)
 {
     if (task.IDTask != -1)
     {
         throw new SchedulerException("Could not insert an inserted task");
     }
     task.SetIDTask(localSchDB.InsertTask(task));
     return(task);
 }
예제 #2
0
        /// <summary>
        /// Insert a new task
        /// </summary>
        /// <param name="task"></param>
        /// <remarks>After a new task is inserted it obtains a IDTask. Before it's -1.</remarks>
        /// <returns></returns>
        public override SchedulerTask InsertTask(SchedulerTask task)
        {
            if (task.IDTask != -1)
            {
                throw new SchedulerException("Could not insert an inserted task");
            }

            task.SetIDTask(localSchDB.InsertTask(task));
            if (_cache.Count != 0 && task.DueTime < ((SchedulerTask)_cache.GetKey(_cache.Count - 1)).DueTime)
            {
                lock (_cache.SyncRoot)
                {
                    _cache.RemoveAt(_cache.Count - 1);
                    _cache.Add(task, task);
                }
            }

            return(task);
        }