Exemplo n.º 1
0
        private async void TimerEvent(object status)
        {
            TimerSector <T> sector = await base.TimerTick().ConfigureAwait(false);

            if (null != sector)
            {
                foreach (TimerItem <T> item in sector.Items)
                {
                    item.Repetition -= 1;
                    if (item.Repetition > 0)
                    {
                        item.ExecutionTick = 0;
                        await this.AddOverflow(item).ConfigureAwait(false);
                    }
                    else
                    {
                        timerItems.Remove(item.TimerItemId);
                    }
                }
                sector.Items.ForEach(item => item.TimerAction.Invoke(item));
            }

            nextTickTime = nextTickTime.AddMilliseconds(this.baseInterval);
            TimeSpan nextInterval = nextTickTime.Subtract(DateTime.UtcNow);

            if (nextInterval.TotalMilliseconds < 0)
            {
                nextInterval = TimeSpan.FromMilliseconds(1);
            }
            timer.Change(nextInterval, Timeout.InfiniteTimeSpan);
        }
Exemplo n.º 2
0
 public TimerSector <T> this[int index]
 {
     get
     {
         if (null == sectors[index])
         {
             sectors[index] = new TimerSector <T>();
         }
         return(sectors[index]);
     }
 }
Exemplo n.º 3
0
        protected async Task <TimerSector <T> > TimerTick()
        {
            currentTick = ++currentTick % this.wheelSize;
            if (0 == currentTick)
            {
                await CarryOver().ConfigureAwait(false);
            }
            await sectorHandling.WaitAsync().ConfigureAwait(false);

            TimerSector <T> sector = sectors[currentTick];

            sectors[currentTick] = null;
            sectorHandling.Release();
            return(sector);
        }
Exemplo n.º 4
0
        private async Task CarryOver()
        {
            if (null != this.carryOverWheel)
            {
                TimerSector <T> sector = await carryOverWheel.TimerTick().ConfigureAwait(false);

                if (null != sector?.Items)
                {
                    foreach (TimerItem <T> item in sector.Items)
                    {
                        int tick = item.ExecutionTick;
                        item.ExecutionTick %= sectorSpan;
                        await this.AddItem((tick / sectorSpan), item).ConfigureAwait(false);
                    }
                }
            }
        }