private static void SetInterval(int intervalMinutes) { try { while (true) { string startInfo = string.Format("{0} Reminding the start", DateTime.Now); ConsoleAndLog(startInfo); _reminderManager.ReminderAll(); string completeInfo = string.Format("{0} Reminding the end.After {1} minutes, it will run again.", DateTime.Now, ReminderConfig.RunTimeInterval()); ConsoleAndLog(completeInfo); //程序暂停一段时间,再次执行 Thread.Sleep(intervalMinutes * 1000 * 60); } } catch (Exception exception) { Console.WriteLine(exception); //异常后,恢复执行 SetInterval(ReminderConfig.RunTimeInterval()); } }
/// <summary> /// 邮件定时提醒:近三天没有处理过的Ticket /// </summary> void Timer_Reminder(object sender, System.Timers.ElapsedEventArgs e) { try { string startInfo = string.Format("{0} Reminding the start", DateTime.Now); WriteLog(startInfo); ReminderManager reminderManager = new ReminderManager(); reminderManager.ReminderAll(); string completeInfo = string.Format("{0} Reminding the end.After {1} minutes, it will run again.", DateTime.Now, ReminderConfig.RunTimeInterval()); WriteLog(completeInfo); } catch (Exception exception) { WriteLog("程序异常:" + exception.Message); } }