Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void Page_Load(object sender, EventArgs e)
- {
- Timer timer = new Timer();
- reminder = 5;
- worker = new BackgroundWorker();
- worker.DoWork += worker_DoWork;
- timer.Elapsed += timer_Elapsed;
- timer.Interval = TimeSpan.FromMinutes(reminder).TotalMilliseconds;
- timer.Enabled = true;
- timer.Start();
- }
- private void timer_Elapsed(object sender, ElapsedEventArgs e)
- {
- if (!worker.IsBusy)
- worker.RunWorkerAsync();
- }
- private void worker_DoWork(object sender, DoWorkEventArgs e)
- {
- //whatever You want the background thread to do...
- doReminders(reminder);
- }
- /// <summary>
- /// Does the reminders.
- /// sends out reminders based on the amount of minuties before a meeting
- /// </summary>
- protected void doReminders(double reminder)
- {
- try
- {
- List<ApertureDal.Appointment> _appointments = _dal.GetAppointmentsByReminderLength(reminder);
- _appointments.ForEach(x =>
- {
- _dal.sendAppointmentEmails(x.ID, x.emailAddress, x.TimeCode, x.emailAddress, new Guid(Constants.calenderEmail), x.CustomerFirstName, x.CustomerLastName, x.managerName, x.preferedContactNumber, x.emailAddress, x.Start, x.End, x.managerId);
- });
- }
- catch (Exception ex)
- {
- }
- }
- }
- /// <summary>
- /// Gets the appointments.
- /// </summary>
- /// <param name="reminderLength">Length of the reminder.</param>
- /// <returns></returns>
- public List<Appointment> GetAppointmentsByReminderLength(double reminderLength)
- {
- List<Appointment> list = new List<Appointment>();
- try
- {
- var q = from a in apertureNetEntities.Appointments.Where(a => a.Start.Value.AddMinutes(-reminderLength) <= DateTime.Now)
- select a;
- list = q.ToList();
- }
- catch (Exception ex)
- {
- string inner = string.Empty;
- if (ex.InnerException != null)
- {
- inner = ex.InnerException.ToString();
- }
- logger.Error("Error in List<Appointment> function GetAppointmentsByReminderLength " + ex.ToString() + " " + inner);
- return null;
- }
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement