void Dispatch(success_t callback = null) { // If the validation failed abort the dispatching here. if (!_predicate()) { return; } // Process all asyncs while (!_asyncHolder.Empty()) { _asyncHolder.First().Invoke(); _asyncHolder.RemoveAt(0); // If the validation failed abort the dispatching here. if (!_predicate()) { return; } } while (!_task_holder.IsEmpty()) { if (_task_holder.First()._end > _now) { break; } // Perfect forward the context to the handler // Use weak references to catch destruction before callbacks. TaskContext context = new TaskContext(_task_holder.Pop(), this); // Invoke the context context.Invoke(); // If the validation failed abort the dispatching here. if (!_predicate()) { return; } } callback?.Invoke(); }
/// <summary> /// Update the scheduler with a difftime. /// Calls the optional callback on successfully finish. /// </summary> /// <param name="difftime"></param> /// <returns></returns> TaskScheduler Update(TimeSpan difftime, success_t callback = null) { _now += difftime; Dispatch(callback); return(this); }
/// <summary> /// Update the scheduler with a difftime in ms. /// Calls the optional callback on successfully finish. /// </summary> /// <param name="milliseconds"></param> /// <returns></returns> public TaskScheduler Update(uint milliseconds, success_t callback = null) { return(Update(TimeSpan.FromMilliseconds(milliseconds), callback)); }
/// <summary> /// Update the scheduler to the current time. /// Calls the optional callback on successfully finish. /// </summary> /// <returns></returns> public TaskScheduler Update(success_t callback = null) { _now = DateTime.Now; Dispatch(callback); return(this); }