Example #1
0
 public static void Stop()
 {
     new GlobalStateManager().ClearTaskLoops();
     TaskLoopScheduler.Terminate();
     TimerHelper.Timer.Stop();
     Logger.Write("Service stopped.", Logger.LogType.ServiceLog);
 }
Example #2
0
        public static void TimerTick(object sender, ElapsedEventArgs e)
        {
            Logger.Write("Entering TimerTick.", Logger.LogType.ServiceLog);

            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    SchedulerId = (SchedulerId + 1) % 4;
                    Logger.Write($"SchedulerId: {SchedulerId}", Logger.LogType.ServiceLog);

                    var tls = new TaskLoopScheduler();
                    var eas = new EventActionScheduler();
                    switch (SchedulerId)
                    {
                    case 0:
                        tls.PollForTasksToStart();
                        tls.StartTasks();
                        break;

                    case 1:
                        eas.PollForEventActionsToStop();
                        eas.StopEventActions();
                        break;

                    case 2:
                        eas.PollForEventActionsToStart();
                        eas.StartEventActions();
                        break;

                    case 3:
                        tls.PollForTasksToStop();
                        tls.StopTasks();
                        break;
                    }

                    Logger.Write($"{new GlobalStateManager().GetCount()} TaskLoop(s) running: {new GlobalStateManager().ToString()}", Logger.LogType.ServiceLog);
                }
                catch (Exception exception)
                {
                    Logger.WriteException(exception);
                }
            });

            Logger.Write("Exiting TimerTick.", Logger.LogType.ServiceLog);

            TimerHelper.Timer.Interval = TimerUtility.GetAdjustedInterval(TimerHelper.TimerTickInterval);
            TimerHelper.Timer.Start();
        }