Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo n.º 3
0
 /// <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));
 }
Exemplo n.º 4
0
 /// <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);
 }