public OneTimeDelayTask(ThreadScheduledExecutor executor, Action command, TimeSpan delay) : base(true)
            {
                this.startTime     = DateTime.Now.Ticks;
                this.delay         = delay;
                this.executor      = executor;
                this.wrappedAction = () =>
                {
                    try
                    {
                        if (this.IsDone)
                        {
                            return;
                        }

                        if (this.IsCancellationRequested)
                        {
                            this.SetCancelled();
                        }
                        else
                        {
                            command();
                            this.SetResult();
                        }
                    }
                    catch (Exception e)
                    {
                        this.SetException(e);
                    }
                };
                this.executor.Add(this);
            }
            public FixedRateDelayTask(ThreadScheduledExecutor executor, Action command, TimeSpan initialDelay, TimeSpan period) : base()
            {
                this.startTime    = DateTime.Now.Ticks;
                this.initialDelay = initialDelay;
                this.period       = period;
                this.executor     = executor;

                this.wrappedAction = () =>
                {
                    try
                    {
                        if (this.IsDone)
                        {
                            return;
                        }

                        if (this.IsCancellationRequested)
                        {
                            this.SetCancelled();
                        }
                        else
                        {
                            Interlocked.Increment(ref count);
                            //count++;
                            this.executor.Add(this);
                            command();
                        }
                    }
                    catch (Exception)
                    {
                    }
                };
                this.executor.Add(this);
            }
Пример #3
0
            public FixedDelayDelayTask(ThreadScheduledExecutor executor, Action command, TimeSpan initialDelay, TimeSpan delay) : base()
            {
                this.delay    = delay;
                this.executor = executor;
                this.nextTime = DateTime.Now + initialDelay;

                this.wrappedAction = () =>
                {
                    try
                    {
                        if (this.IsDone)
                        {
                            return;
                        }

                        if (this.IsCancellationRequested)
                        {
                            this.SetCancelled();
                        }
                        else
                        {
                            command();
                        }
                    }
                    catch (Exception e)
                    {
#if DEBUG
                        if (log.IsWarnEnabled)
                        {
                            log.Warn(e);
                        }
#endif
                    }
                    finally
                    {
                        if (this.IsCancellationRequested)
                        {
                            this.SetCancelled();
                        }
                        else
                        {
                            //this.nextDelay = this.nextDelay.Add(this.delay);
                            this.nextTime = DateTime.Now + this.delay;
                            this.executor.Add(this);
                        }
                    }
                };
                this.executor.Add(this);
            }
            public FixedDelayDelayTask(ThreadScheduledExecutor executor, Action command, TimeSpan initialDelay, TimeSpan delay) : base()
            {
                //this.startTime = DateTime.Now.Ticks;
                this.delay    = delay;
                this.executor = executor;
                //this.nextDelay = initialDelay;
                this.nextTime = DateTime.Now + initialDelay;

                this.wrappedAction = () =>
                {
                    try
                    {
                        if (this.IsDone)
                        {
                            return;
                        }

                        if (this.IsCancellationRequested)
                        {
                            this.SetCancelled();
                        }
                        else
                        {
                            command();
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        if (this.IsCancellationRequested)
                        {
                            this.SetCancelled();
                        }
                        else
                        {
                            //this.nextDelay = this.nextDelay.Add(this.delay);
                            this.nextTime = DateTime.Now + this.delay;
                            this.executor.Add(this);
                        }
                    }
                };
                this.executor.Add(this);
            }