Last active
December 18, 2015 13:19
-
-
Save yemrekeskin/5789267 to your computer and use it in GitHub Desktop.
Scheduled Task to send email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Sample.EmailMechanism | |
| { | |
| public class NotificationController | |
| { | |
| public NotificationController() { } | |
| public void Check() | |
| { | |
| NotificationRepository repository = new NotificationRepository(); | |
| IEnumerable<NotificationMessage> list = repository.SelectNotification(); | |
| bool controldummy; | |
| foreach (NotificationMessage item in list) | |
| { | |
| try | |
| { | |
| EmailHelper.SendEmail(item); | |
| controldummy = true; | |
| } | |
| catch (Exception) | |
| { | |
| controldummy = false; | |
| item.Status = EmailStatus.ERROR; | |
| item.TryCount++; | |
| repository.UpdateNotification(item); | |
| } | |
| if (controldummy) | |
| { | |
| item.Status = EmailStatus.SEND; | |
| item.TryCount++; | |
| repository.UpdateNotification(item); | |
| } | |
| } | |
| } | |
| } | |
| public class Job | |
| { | |
| public Job() { } | |
| public static void Testit(object state) | |
| { | |
| Console.WriteLine("Called..."); | |
| } | |
| public static void CheckEmails(object state) | |
| { | |
| NotificationController controller = new NotificationController(); | |
| controller.Check(); | |
| } | |
| } | |
| public class Scheduler | |
| { | |
| public Scheduler() { } | |
| public void Scheduler_Start() | |
| { | |
| //TimerCallback callbackMinute = new TimerCallback(Job.Testit); | |
| //Timer minuteTimer = new Timer(callbackMinute, null, TimeSpan.Zero, TimeSpan.FromSeconds(1.0)); | |
| TimerCallback callbackSecond = new TimerCallback(Job.CheckEmails); | |
| Timer minuteTimer = new Timer(callbackSecond, null, TimeSpan.Zero, TimeSpan.FromSeconds(10.0)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment