Example #1
0
        private ServiceTimer CreateTimer(ServiceEntity entity)
        {
            ServiceTimer timer = new ServiceTimer(entity.Interval * 1000);

            timer.ServiceEntity = entity;
            timer.AutoReset     = true;
            timer.Elapsed      += new ElapsedEventHandler(timer_Elapsed);
            timer.Enabled       = true;
            timer.Start();

            this.timer_Elapsed(timer, null);

            return(timer);
        }
Example #2
0
        private void ResetTimers()
        {
            List <ServiceEntity> serviceEntities = ConfigurationManager.GetSection("ServiceEntities") as List <ServiceEntity>;

            try
            {
                foreach (ServiceTimer timer in serviceTimers)
                {
                    timer.Disabled = true;
                }
                foreach (ServiceEntity se in serviceEntities)
                {
                    ServiceTimer existTimer = serviceTimers.Find(new Predicate <ServiceTimer>(delegate(ServiceTimer service)
                    {
                        if (string.Compare(service.ServiceEntity.Key, se.Key, true) == 0)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }));

                    if (existTimer == null)
                    {
                        serviceTimers.Add(CreateTimer(se));
                    }
                    else
                    {
                        existTimer.Interval      = se.Interval * 1000;
                        existTimer.ServiceEntity = se;
                        existTimer.Disabled      = false;
                    }
                }
                for (int i = serviceTimers.Count - 1; i >= 0; i--)
                {
                    if (serviceTimers[i].Disabled)
                    {
                        serviceTimers.Remove(serviceTimers[i]);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }