예제 #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);
        }
예제 #2
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);
 }
        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);
        }