protected virtual void OnScheduleElapsed(ScheduleEventArgs args)
 {
     if (ScheduleElapsed != null)
     {
         ScheduleElapsed(this, args);
     }
 }
        protected void OnScheduleElapsed(ScheduleEventArgs args)
        {
            string tsk = args.Settings.GetString("task");
            var t = _taskFactory.CreateObject(tsk);

            Try.Do(() => t.Execute(), error =>
            {
                //errorHandler(error);
            });
        }
 private void _ScheduleElapsed(object sender, ScheduleEventArgs e)
 {
     try
     {
         OnScheduleElapsed(e);
     }
     catch (ThreadAbortException)
     {
         //do nothing
     }
 }
 private void _ScheduleExpired(object sender, ScheduleEventArgs e)
 {
     ScheduleManager.RemoveSchedule(e.Schedule);
 }
        private static void StartScheduler()
        {
            while (!_stopScheduler.WaitOne(_schedulerInterval, false))
            {
                try
                {
                    foreach (ScheduleBase schedule in GetSchedules())
                    {
                        if (schedule.Enabled)
                        {
                            bool isNotRunning = false;

                            if (!_elapseExpires.HasKey(schedule.Name))
                            {
                                lock (_elapseExpiresSyncLock)
                                {
                                    if (!_elapseExpires.HasKey(schedule.Name))
                                    {
                                        _elapseExpires.Add(schedule);
                                        isNotRunning = true;
                                    }
                                }
                            }

                            if (isNotRunning)
                            {
                                bool hasElapsed = schedule.HasElapsed();
                                bool hasExpired = schedule.HasExpired();

                                if (hasElapsed)
                                {
                                    schedule.Settings.LastElapsed = DateTime.Now;

                                }

                                if (hasExpired)
                                {
                                    schedule.Settings.DateExpired = DateTime.Now;

                                }

                                if (hasElapsed || hasExpired)
                                {
                                    ScheduleEventArgs eventArgs = new ScheduleEventArgs(schedule, schedule.Settings);
                                    Thread newThread = new Thread(new ParameterizedThreadStart(ElapseExpire));
                                    newThread.Name = schedule.Name;
                                    newThread.Start(new object[] { eventArgs, hasElapsed, hasExpired });
                                }
                                else
                                {
                                    RemoveRunning(schedule);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    //_logger.Error(e);
                }
            }
        }
        private void _ScheduleElapsed(object sender, ScheduleEventArgs e)
        {
            if (!_isFatalException)
            {
                try
                {
                    OnScheduleElapsed(e);
                }
                catch (ThreadAbortException)
                {
                    // do nothing.
                }
                catch (Exception)
                {
                    if (!e.Settings.Contains(EXCEPTION_COUNT_SETTING_NAME))
                    {
                        e.Settings.Add(EXCEPTION_COUNT_SETTING_NAME, 0);
                    }

                     int exceptions = e.Settings.GetInt32(EXCEPTION_COUNT_SETTING_NAME);
                    e.Settings.LastElapsed = new DateTime(0);

                    if (++exceptions <= EXCEPTION_COUNT_MAXIMUM_VALUE)
                    {
                        e.Settings.SetValue(EXCEPTION_COUNT_SETTING_NAME, exceptions);
                    }
                    else
                    {
                        e.Settings.Remove(EXCEPTION_COUNT_SETTING_NAME);

                        _isFatalException = true;
                        throw;
                    }
                }
            }
        }
 /// <summary>
 /// Called when the schedule has expired.
 /// </summary>
 protected internal virtual void OnExpired(ScheduleEventArgs args)
 {
     if (Expired != null)
     {
         Expired(this, args);
     }
 }