Exemple #1
0
            public IDisposable Schedule(TimeSpan dueTime, Action action)
            {
                if (action == null)
                {
                    throw new ArgumentNullException("action");
                }

                var dt = Time + Scheduler.Normalize(dueTime);

                var si = new ScheduledItem(action, dt);

                var queue = GetQueue();

                if (queue == null)
                {
                    queue = new SchedulerQueue(4);
                    queue.Enqueue(si);

                    CurrentThreadScheduler.SetQueue(queue);
                    try
                    {
                        Trampoline.Run(queue);
                    }
                    finally
                    {
                        CurrentThreadScheduler.SetQueue(null);
                    }
                }
                else
                {
                    queue.Enqueue(si);
                }

                return(si.Cancellation);
            }
Exemple #2
0
 /// <summary>
 /// Removes the specified work item from the scheduler queue.
 /// </summary>
 /// <param name="scheduledItem">Work item to be removed from the scheduler queue.</param>
 /// <returns>true if the item was found; false otherwise.</returns>
 public bool Remove(ScheduledItem scheduledItem)
 {
     return(mQueue.Remove(scheduledItem));
 }
Exemple #3
0
 /// <summary>
 /// Enqueues the specified work item to be scheduled.
 /// </summary>
 /// <param name="scheduledItem">Work item to be scheduled.</param>
 public void Enqueue(ScheduledItem scheduledItem)
 {
     mQueue.Enqueue(scheduledItem);
 }