protected override void OnStart(string[] args) { eventLog.WriteEntry("In OnStart."); RequestBL.OnInitMapper(); timer.Interval = 300000; // 5 minute timer.Elapsed += new ElapsedEventHandler(GetAllRelevantRequests); timer.Start(); //timer.Enabled = true; }
protected override void OnStart(string[] args) { eventLog.WriteEntry("In OnStart."); // set the time the service start and setting the time period for each round TimeSpan scheduledRunTime = new TimeSpan(20, 8, 0), timeBetweenEachRun = new TimeSpan(0, 5, 0); double current = DateTime.Now.TimeOfDay.TotalMilliseconds; double scheduledTime = scheduledRunTime.TotalMilliseconds; double intervalPeriod = timeBetweenEachRun.TotalMilliseconds; // calculates the first execution of the method, either its today at the scheduled time or tomorrow (if scheduled time has already occurred today) double firstExecution = current > scheduledTime ? intervalPeriod - (current - scheduledTime) : scheduledTime - current; // create callback - this is the method that is called on every interval TimerCallback callback = new TimerCallback(Monitoring); // create timer timer = new System.Threading.Timer(callback, null, Convert.ToInt32(firstExecution), Convert.ToInt32(intervalPeriod)); // initialization the mapper RequestBL.OnInitMapper(eventLog); }