Пример #1
0
        public CancellationTokenSource schedule(Action task, long delayInMillis)
        {
            var source           = new CancellationTokenSource();
            CancellationToken ct = source.Token;

            lock (currentTasks)
            {
                Task tsk_p = Task.Factory.StartNew(async(obj) =>
                {
                    await Task.Delay(TimeSpan.FromMilliseconds(delayInMillis));

                    CancellationToken token = (CancellationToken)obj;

                    if (token.IsCancellationRequested)
                    {
                        log.Debug("Cancellation requested, nothing to do.");
                    }
                    else
                    {
                        // await Task.Run(task);
                        executor.execute(task);
                    }
                }, ct);
                cancs[tsk_p] = source;
                tsk_p.ContinueWith((antecedent, fu) =>
                {
                    this.Dequeue(tsk_p);
                }, this);
                // currentTasks.Push(tsk_p);
                // log.Debug("Push +1 task.");
            }

            return(source);
        }
 public virtual void queue(Action task)
 {
     queue_Renamed.execute(task);
 }
 public virtual void execute(S source, Action runnable)
 {
     executor.execute(runnable);
     // scheduler.schedule(runnable, 0);
 }