Ejemplo n.º 1
0
        private static void MessageLoop(CancellationToken token)
        {
            try
            {
                while (true)
                {
                    token.ThrowIfCancellationRequested();
                    var date = DateTime.UtcNow.ToTimeZone(_tz);
                    ResetAlertsIfNewDay(date);
                    _birthdays.CongratulateTheUngratulated(date, Config.MessageTemplate);
                    _messagingApi.Fetch();
                    token.WaitHandle.WaitOne(Config.MessageLoopSleepTimeMs);
                }
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("Exiting");
            }
            catch (ObjectDisposedException)
            {
                Console.WriteLine("Exiting");
            }

            OnExit();
            Environment.Exit(0); // exit without waiting for the blocked ReadLine() in Start()
        }