static void Main(string[] args)
        {
            logger.Info("The application has started.");

            PISystem pisystem = new PISystems().DefaultPISystem;

            pisystem.Connect();
            logger.Info($"Connecting as: {pisystem.CurrentUserIdentityString}");
            AFDatabase configuration = pisystem.Databases["Configuration"];
            AFElements preferences   = configuration.Elements["LimitCalculator"].Elements;

            logger.Info($"Will process {preferences.Count} preferences");

            List <DatabaseMonitoring> monitoredDB = new List <DatabaseMonitoring> {
            };

            Parallel.ForEach(preferences, (preference) =>
            {
                string JSON = (string)preference.Attributes["configuration"].GetValue().Value;
                logger.Info($"Configuration for preference: {JSON}");
                LimitCalculation calc = new LimitCalculation(CalculationPreference.CalculationPreferenceFromJSON(JSON), preference.Name);
                monitoredDB.Add(new DatabaseMonitoring(calc));
            });

            WaitForQuit();
        }
        public DatabaseMonitoring(LimitCalculation calculation)
        {
            this.calculation = calculation;
            afdatabase       = calculation.afdatabase;
            logger.Info($"Monitoring the database: {afdatabase}");
            // Initialize the cookie (bookmark)
            afdatabase.FindChangedItems(false, int.MaxValue, null, out cookie);

            refreshTimer.Elapsed += new ElapsedEventHandler(OnElapsed);
            afdatabase.Changed   += new EventHandler <AFChangedEventArgs>(OnChanged);
            refreshTimer.Start();
        }