예제 #1
0
        // THIS METHOD FIRES ON THE OLD TIMER'S ELAPSED EVENT
        //public void OnTimer(object sender, ElapsedEventArgs args)
        //{
        //    // Refresh APIHandler Configuration Information
        //    apiHandler.Refresh(ref eventId);
        //    // Refresh APIData Information
        //    excelData.Refresh(apiHandler.cm, ref eventId, eventLog1);
        //    eventId++;
        //    // Begin API Agent Queue Update
        //    eventLog1.WriteEntry("Beginning Agent Queue Update.", EventLogEntryType.Information, eventId++);
        //    apiHandler.ExcelQueueUpdate(excelData, ref eventId);
        //}
        public void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            // Refresh APIHandler Configuration Information
            apiHandler.Refresh(ref eventId);
            // Refresh APIData Information
            excelData.Refresh(apiHandler.cm, ref eventId, eventLog1);
            eventId++;
            // Begin API Agent Queue Update
            eventLog1.WriteEntry("Beginning Agent Queue Update.", EventLogEntryType.Information, eventId++);
            apiHandler.ExcelQueueUpdate(excelData, ref eventId);

            // Set Timer Interval for next runtime to 1 hour in the future
            if (_timer.Interval != 1 * 60 * 60 * 1000)
            {
                _timer.Interval = 1 * 60 * 60 * 1000;
            }
        }
예제 #2
0
        protected override void OnStart(string[] args)
        {
            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            eventLog1.WriteEntry("Service Initiating...", EventLogEntryType.Information, eventId++);

            //OLD TIMER, ONLY EXECUTED ON INTERVAL
            //Initialize Timer Object to poll when the service should run
            //Timer timer = new Timer();
            //timer.Interval = 120000; // 2 minutes
            //timer.Elapsed += new ElapsedEventHandler(this.OnTimer);
            //timer.Start();


            // Set initial Interval to the difference in milliseconds from current time and the scheduled time
            _timer.Enabled  = true;
            _timer.Interval = _scheduleTime.Subtract(DateTime.Now).TotalSeconds * 1000;
            _timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);


            // Initialize APIHandler to route commands through
            apiHandler = new APIHandler();
            apiHandler.SetEventLog(eventLog1);
            apiHandler.Refresh(ref eventId);

            // Initialize ExcelData
            excelData = new ExcelData(eventLog1);
            excelData.Refresh(apiHandler.cm, ref eventId, eventLog1);
            eventId++;
            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            eventLog1.WriteEntry("Service Started.", EventLogEntryType.Information, eventId++);
        }