Ejemplo n.º 1
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     if (Environment.UserInteractive)
     {
         SchedulerPCComApiService service = new SchedulerPCComApiService();
         service.TestStartupAndStop(args);
     }
     else
     {
         ServiceBase[] ServicesToRun;
         ServicesToRun = new ServiceBase[]
         {
             new SchedulerPCComApiService()
         };
         ServiceBase.Run(ServicesToRun);
     }
 }
Ejemplo n.º 2
0
        public CyclicOperationTimer(int hour, int minute, int second, int periode, IList <Site> siteList, SchedulerPCComApiService scheduler)
        {
            var periodConverted = new TimeSpan(periode, 0, 0);

            int periodMilisec = (int)periodConverted.TotalMilliseconds;

            pScheduler = scheduler;

            var dueTime = 0;

            _timer = new  Timer(
                callback: this._timer_Elapsed,
                state: siteList,
                dueTime: dueTime, // décompte avant le début du timer ( 0 = depart immédiat)
                period: periodMilisec
                );

            // Figure how much time until 4:00
            //DateTime fourOClock = DateTime.Today.AddHours(16.0);
            DateTime now        = DateTime.Now;
            DateTime hourOClock = DateTime.Today.AddHours(hour);

            hourOClock = hourOClock.AddMinutes(minute);
            hourOClock = hourOClock.AddSeconds(second);

            // If it's already past 4:00, wait until 4:00 tomorrow
            if (now > hourOClock)
            {
                hourOClock = hourOClock.AddDays(1.0);
            }

            int msUntilFour = (int)((hourOClock - now).TotalMilliseconds);

            // Set the timer to elapse only once, at 4:00.
            _timer.Change(msUntilFour, periodMilisec);
        }