Пример #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();
     }
 }
Пример #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);
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Starts an async task.
        /// </summary>
        /// <param name="action">The action to launch async.</param>
        /// <param name="isImportant">Whether this action is considered important.</param>
        /// <returns>The scheduled item.</returns>
        public ASyncScheduleItem StartAsyncTask(Action action, bool isImportant = false)
        {
            ASyncScheduleItem asyncer = new ASyncScheduleItem()
            {
                OwningEngine = this, MyAction = action, UnImportant = !isImportant
            };

            asyncer.RunMe();
            return(asyncer);
        }
Пример #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;
         }
     }
 }