public static void MainFunction(object sender, System.Timers.ElapsedEventArgs args) { Managers.NotificationManager.NotificationSchedulMacker(); Managers.NotificationManager.NotificationMacker(); Managers.NotificationManager.SubmitForReview(); using (NotificationData data = new NotificationData()) { string result = ""; List <Notification> sendingList = data.GetMany(x => x.SentStatus == 0).ToList(); foreach (Notification item in sendingList) { result = SendEmail(item.SendTo, item.Subject, item.Text); if (result == "success") { item.SentStatus = 1; item.StatusMessage = "successfully sent"; item.SentDate = DateTime.Now; } else { item.SentStatus = 2; item.StatusMessage = result; } data.Update(item); } data.Commit(); } }