Ejemplo n.º 1
0
        private void DoContinuousWork(WorkThreadConfiguration configuration)
        {
            bool     firstPass = true;
            TimeSpan interval  = configuration.Work.Interval;

            if (configuration.Work.StartImmediately)
            {
                configuration.Work.Interval = TimeSpan.FromSeconds(0);
            }
            else if (configuration.Work.StartDelay > TimeSpan.Zero)
            {
                configuration.Work.Interval = configuration.Work.StartDelay;
            }
            uint workRepeatCounter = 0;

            while (!configuration.ShutdownEvent.WaitOne(configuration.Work.Interval, true))
            {
                this.DoWork(configuration.Work);
                if (configuration.Work.StartImmediately && firstPass || configuration.Work.StartDelay > TimeSpan.Zero && firstPass)
                {
                    configuration.Work.Interval = interval;
                    firstPass = false;
                }
                if (configuration.Work.RepeatTimes <= 0)
                {
                    continue;
                }
                workRepeatCounter++;
                if (workRepeatCounter != configuration.Work.RepeatTimes)
                {
                    continue;
                }
                return;
            }
        }
Ejemplo n.º 2
0
 public Scheduler(IWork[] work)
 {
     if (work == null)
     {
         throw new ArgumentNullException();
     }
     if ((int)work.Length == 0)
     {
         throw new ArgumentOutOfRangeException();
     }
     this.SetupHostingEnvironment();
     this._configurations = new WorkThreadConfiguration[(int)work.Length];
     for (int i = 0; i < (int)this._configurations.Length; i++)
     {
         WorkThreadConfiguration workThreadConfiguration = new WorkThreadConfiguration()
         {
             ShutdownEvent = new ManualResetEvent(false),
             Work          = work[i]
         };
         this._configurations[i] = workThreadConfiguration;
     }
 }