Esempio n. 1
0
 /// <summary>
 /// Internal runner for the item.
 /// </summary>
 private void RunInternal()
 {
     try
     {
         if (UnImportant)
         {
             Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
         }
         MyAction.Invoke();
     }
     catch (Exception ex)
     {
         if (ex is ThreadAbortException)
         {
             throw;
         }
         SysConsole.Output("Running Asynchronous task", ex);
     }
     finally
     {
         Thread.CurrentThread.Priority = ThreadPriority.Normal;
     }
     lock (Locker)
     {
         Done = true;
     }
     if (FollowUp != null)
     {
         FollowUp.RunMe();
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Replaces the schedule item if its not yet started, otherwises follows it with a new item.
 /// </summary>
 /// <param name="item">The replacement item.</param>
 /// <returns>The final item.</returns>
 public ASyncScheduleItem ReplaceOrFollowWith(ASyncScheduleItem item)
 {
     lock (Locker)
     {
         if (FollowUp != null)
         {
             return(FollowUp.ReplaceOrFollowWith(item));
         }
         if (Started)
         {
             if (Done)
             {
                 item.RunMe();
                 return(item);
             }
             else
             {
                 FollowUp = item;
                 return(item);
             }
         }
         else
         {
             MyAction = item.MyAction;
             FollowUp = item.FollowUp;
             return(this);
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Starts an async task.
        /// </summary>
        /// <param name="a">The action to launch async.</param>
        /// <param name="prio">Whether this action is considered important.</param>
        /// <returns>The scheduled item.</returns>
        public ASyncScheduleItem StartAsyncTask(Action a, bool prio = false)
        {
            ASyncScheduleItem asyncer = new ASyncScheduleItem()
            {
                OwningEngine = this, MyAction = a, UnImportant = !prio
            };

            asyncer.RunMe();
            return(asyncer);
        }
Esempio n. 4
0
 /// <summary>
 /// Tells the item to follow the current item with a new one.
 /// </summary>
 /// <param name="item">The follower item.</param>
 public void FollowWith(ASyncScheduleItem item)
 {
     lock (Locker)
     {
         if (Done)
         {
             item.RunMe();
         }
         else
         {
             FollowUp = item;
         }
     }
 }