public DateTime GetNextRunTime(DateTime lastScheduledRunTime, DateTime lastCompleteTime)
            {
                if (!_hasRun.Exchange(true))
                {
                    return(new DateTime());
                }
                _latch.CountDown();

                return(default(DateTime));
            }
Beispiel #2
0
        internal void ContinueWithCore(Task continuation, TaskContinuationOptions kind,
                                       TaskScheduler scheduler, Func <bool> predicate)
        {
            // Already set the scheduler so that user can call Wait and that sort of stuff
            continuation.taskScheduler = scheduler;
            continuation.scheduler     = ProxifyScheduler(scheduler);

            AtomicBoolean launched = new AtomicBoolean();
            EventHandler  action   = delegate {
                if (!predicate())
                {
                    return;
                }

                if (!launched.Value && !launched.Exchange(true))
                {
                    if (!ContinuationStatusCheck(kind))
                    {
                        continuation.Cancel();
                        continuation.CancelReal();
                        continuation.Dispose();

                        return;
                    }

                    CheckAndSchedule(continuation, kind, scheduler);
                }
            };

            if (IsCompleted)
            {
                action(this, EventArgs.Empty);
                return;
            }

            completed += action;

            // Retry in case completion was achieved but event adding was too late
            if (IsCompleted)
            {
                action(this, EventArgs.Empty);
            }
        }