Beispiel #1
0
 internal void DeallocateTimer(LightWeightTimer timer, LightWeightTimerTimeClass timeClass)
 {
     lock (_timeClasses)
     {
         timeClass.DeallocateTimer(timer);
         if (timeClass.Count == 0)
         {
             _timeClasses.Remove(timeClass);
             _timeClassesByTimeSpan.Remove(timeClass.Interval);
         }
     }
 }
Beispiel #2
0
 public LightWeightTimer AllocateTimer(TimeSpan interval)
 {
     lock (_timeClasses)
     {
         if (!_timeClassesByTimeSpan.TryGetValue(interval, out LightWeightTimerTimeClass timeClass))
         {
             timeClass = new LightWeightTimerTimeClass(this, interval);
             _timeClasses.Add(timeClass);
             _timeClassesByTimeSpan[interval] = timeClass;
         }
         return(timeClass.AllocateTimer());
     }
 }
Beispiel #3
0
        private void Execute(object obj)
        {
            if (Started != null)
            {
                Started(this, new EventArgs());
            }
            while (!Terminated)
            {
                try
                {
                    int i = 0;
                    LightWeightTimerTimeClass timeClass = null;

                    do
                    {
                        lock (_timeClasses)
                        {
                            if (i < _timeClasses.Count)
                            {
                                timeClass = _timeClasses[i];
                            }
                            else
                            {
                                timeClass = null;
                            }
                            i++;
                        }
                        if (timeClass != null)
                        {
                            timeClass.Execute();
                        }
                    }while (timeClass != null);
                    Thread.Sleep(1);
                }
                catch (Exception)
                {
                    // TODO : Manage exceptions properly
                }
            }
        }
Beispiel #4
0
 internal LightWeightTimer(LightWeightTimerTimeClass timeClass,
                           LightWeightTimerScheduler scheduler)
 {
     TimeClass = timeClass;
     Scheduler = scheduler;
 }
 internal void DeallocateTimer(LightWeightTimer timer, LightWeightTimerTimeClass timeClass)
 {
     lock (_timeClasses)
     {
         timeClass.DeallocateTimer(timer);
         if (timeClass.Count == 0)
         {
             _timeClasses.Remove(timeClass);
             _timeClassesByTimeSpan.Remove(timeClass.Interval);
         }
     }
 }
 public LightWeightTimer AllocateTimer(TimeSpan interval)
 {
     lock (_timeClasses)
     {
         LightWeightTimerTimeClass timeClass;
         if (!_timeClassesByTimeSpan.TryGetValue(interval, out timeClass))
         {
             timeClass = new LightWeightTimerTimeClass(this, interval);
             _timeClasses.Add(timeClass);
             _timeClassesByTimeSpan[interval] = timeClass;
         }
         return timeClass.AllocateTimer();
     }
 }
 internal LightWeightTimer(LightWeightTimerTimeClass timeClass,
     LightWeightTimerScheduler scheduler)
 {
     TimeClass = timeClass;
     Scheduler = scheduler;
 }