void Remove(TestSchedulerTaskKey key)
 {
     lock (this)
     {
         queue.Remove(key);
     }
 }
 void Add(TestSchedulerTaskKey key, Action task)
 {
     lock (this)
     {
         queue.Add(key, task);
     }
 }
        IDisposable ScheduleActual <TState>(TState state, DateTimeOffset dueTime, Func <IScheduler, TState, IDisposable> action)
        {
            var key = new TestSchedulerTaskKey(Interlocked.Increment(ref index), dueTime);

            Add(key, () => {
                key.SetNext(action(this, state));
            });
            return(key);
        }
 bool TryPeek(out TestSchedulerTaskKey key, out Action task)
 {
     lock (this)
     {
         if (queue.Count == 0)
         {
             key  = default(TestSchedulerTaskKey);
             task = default(Action);
             return(false);
         }
         key  = queue.Keys[0];
         task = queue.Values[0];
         return(true);
     }
 }