public static void RunEventSchedule() { try { ScheduleHistory objScheduleHistory = null; List <Schedule> schedules = SchedulerController.GetTasks(); foreach (Schedule schedule in schedules) { objScheduleHistory = new ScheduleHistory(schedule); //check && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && if (!IsInQueue(objScheduleHistory) && !IsInProgress(objScheduleHistory) && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && objScheduleHistory.IsEnable) { objScheduleHistory.Status = null; AddToScheduleQueue(objScheduleHistory); } } while (GetScheduleQueueCount() > 0) { SetScheduleStatus(ScheduleStatus.RUNNING_EVENT_SCHEDULE); //Fire off the events that need running. if (GetScheduleQueueCount() > 0) { FireEvents(true); } if (_writerTimeouts > 20 || _readerTimeouts > 20) { //Wait for 10 minutes so we don't fill up the logs Thread.Sleep(TimeSpan.FromMinutes(10)); } else { //Wait for 10 seconds to avoid cpu overutilization Thread.Sleep(TimeSpan.FromSeconds(10)); } if (GetScheduleQueueCount() == 0) { return; } } } catch (Exception exc) { ErrorLogger.SchedulerProcessException(exc); } }
public static void Start() { for (int i = 0; i <= 30; i++) { Thread.Sleep(1000); } try { ActiveThreadCount = 0; while (KeepRunning) { try { ForceReloadSchedule = false; ScheduleHistory objScheduleHistory = null; List <Schedule> schedules = SchedulerController.GetTasks(); foreach (Schedule schedule in schedules) { objScheduleHistory = new ScheduleHistory(schedule); //check && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && if (!IsInQueue(objScheduleHistory) && !IsInProgress(objScheduleHistory) && (objScheduleHistory.Status == false || objScheduleHistory.Status == null) && objScheduleHistory.IsEnable) { objScheduleHistory.Status = null; AddToScheduleQueue(objScheduleHistory); } } DateTime lastQueueRefresh = DateTime.Now; bool refreshQueueSchedule = false; while (FreeThreads > 0 && KeepRunning && !ForceReloadSchedule) { if (GetScheduleQueueCount() > 0) { FireEvents(true); } if (KeepThreadAlive == false) { return; } if (_writerTimeouts > 20 || _readerTimeouts > 20) { if (KeepRunning) { Thread.Sleep(TimeSpan.FromMinutes(10)); } else { return; } } else { if (KeepRunning) { Thread.Sleep(TimeSpan.FromSeconds(10)); } else { return; } if ((lastQueueRefresh.AddMinutes(10) <= DateTime.Now || ForceReloadSchedule) && FreeThreads == _maxThreadCount) { refreshQueueSchedule = true; break; } } } if (KeepRunning) { if (refreshQueueSchedule == false) { SetScheduleStatus(ScheduleStatus.WAITING_FOR_OPEN_THREAD); // Thread.Sleep(10000); //sleep for 10 seconds } } else { return; } } catch (Exception exc) { ErrorLogger.SchedulerProcessException(exc); //sleep for 10 minutes //Thread.Sleep(600000); } } } finally { SetScheduleStatus(ScheduleStatus.STOPPED); KeepRunning = false; ActiveThreadCount = 0; } }