/// <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); } } }
/// <summary> /// Creates but does not start an async task. /// </summary> /// <param name="a">The action to launch async.</param> /// <param name="followUp">Optional followup task.</param> /// <returns>The created schedule item.</returns> public ASyncScheduleItem AddAsyncTask(Action a, ASyncScheduleItem followUp = null) { ASyncScheduleItem asyncer = new ASyncScheduleItem() { OwningEngine = this, MyAction = a, FollowUp = followUp }; return(asyncer); }
/// <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); }
/// <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; } } }