Example #1
0
        public IDisposable Schedule(Action task, TimeSpan initialDelay, TimeSpan period, IWorkerServices worker = null)
        {
            if (Prepare())
            {
                var run = runner;

                var t = new InterruptibleAction(task, true);
                t.parent = worker;

                if (worker == null || worker.AddAction(t))
                {
                    var d = timed.Schedule(() =>
                    {
                        if (!t.IsDisposed)
                        {
                            run.Offer(t.Run);
                        }
                    }, initialDelay, period);
                    DisposableHelper.Replace(ref t.resource, d);

                    return(t);
                }
            }
            return(EmptyDisposable.Instance);
        }
            public IDisposable Schedule(Action task)
            {
                if (Volatile.Read(ref cancelled) != 0)
                {
                    return(EmptyDisposable.Instance);
                }
                var t = new InterruptibleAction(task);

                queue.Offer(t);
                Drain();
                return(t);
            }
 public void DeleteAction(InterruptibleAction action)
 {
     if (Volatile.Read(ref disposed) == 0)
     {
         lock (this)
         {
             var set = tasks;
             if (set != null)
             {
                 set.Remove(action);
             }
         }
     }
 }
 public IDisposable Schedule(Action task, TimeSpan initialDelay, TimeSpan period)
 {
     if (Volatile.Read(ref disposed) == 0)
     {
         InterruptibleAction ia = new InterruptibleAction(task, true);
         ia.parent = this;
         if (AddAction(ia))
         {
             var d = shared.Schedule(ia.Run, initialDelay, period);
             DisposableHelper.Replace(ref ia.resource, d);
             return(ia);
         }
     }
     return(EmptyDisposable.Instance);
 }
Example #5
0
 public IDisposable Schedule(Action task, IWorkerServices worker = null)
 {
     if (Prepare())
     {
         InterruptibleAction ia = new InterruptibleAction(task);
         ia.parent = worker;
         if (worker == null || worker.AddAction(ia))
         {
             if (runner.Offer(ia.Run))
             {
                 return(ia);
             }
         }
     }
     return(EmptyDisposable.Instance);
 }
 public bool AddAction(InterruptibleAction action)
 {
     if (Volatile.Read(ref disposed) == 0)
     {
         lock (this)
         {
             var set = tasks;
             if (set != null)
             {
                 set.Add(action);
                 return(true);
             }
         }
     }
     return(false);
 }
            public IDisposable Schedule(Action task, TimeSpan initialDelay, TimeSpan period)
            {
                var cts = new CancellationTokenSource();

                var t = new InterruptibleAction(task);

                cts.Token.Register(t.Dispose);

                SchedulerHelper.ScheduleTask(() =>
                {
                    if (!t.IsDisposed)
                    {
                        queue.Offer(t);
                        Drain();
                    }
                }, initialDelay, period, cts);

                return(cts);
            }
            public IDisposable Schedule(Action task, TimeSpan delay)
            {
                if (Volatile.Read(ref cancelled) != 0)
                {
                    return(EmptyDisposable.Instance);
                }
                var cts = new CancellationTokenSource();

                var t = new InterruptibleAction(task);

                cts.Token.Register(t.Dispose);

                Task.Delay(delay, cts.Token).ContinueWith(a =>
                {
                    queue.Offer(t);
                    Drain();
                }, cts.Token);

                return(cts);
            }
        IDisposable Schedule(Action task, TimeSpan delay, IWorkerServices worker = null)
        {
            if (Volatile.Read(ref state) != 2)
            {
                var run = runner;
                var t   = new InterruptibleAction(task);
                t.parent = worker;
                if (worker == null || worker.AddAction(t))
                {
                    var d = timed.Schedule(() =>
                    {
                        run.Offer(t.Run);
                    }, delay);

                    DisposableHelper.Replace(ref t.resource, d);

                    return(t);
                }
            }
            return(EmptyDisposable.Instance);
        }