Search code examples
c#asp.nettimer

Timer to throw Method Once a Week - C#, Asp.NET


I'm fairly new to C# and coding in general. I'm looking for an example/open source Timer Function that will be used to throw a basic method (ex. Email Notifications) once a week at a certain time. After doing some research I've found that using a Timer instead of a Windows Service would be wise as it will have a very small workload.

I've found a couple timer API's on CodePlex and Code Project but am having trouble working my way through the Examples due to my minimal knowledge of C#.

Does anyone know of a Simple timer that I could use that is Beginner friendly and that also has a walk through? Or is there a simpler way of doing this using System.Timers?

My end goal is to have a timer that will fire a Method at 8:00AM every Monday.

EDIT: I believe I should have been more detailed in my initial Post. The reason I chose not to use the Windows Task Scheduler is because the Method I am invoking is more complex than just invoking Windows Task.

When the timer hits the scheduled time it will fire a Method which queries the DB for Items requiring service within a certain time-frame. This will then loop through the items adding them to an email which will be sent to that Warehouse's Admin.

If I'm not mistaken, that cannot be done through Windows Task Scheduler?


Solution

  • Using a timer for this makes no sense. Your goal is to have a function fire at a specific time. What if your server reboots? Is your timer going to calculate the exact time between the reboot time and Monday at 8:00 am?

    IMO, use a console application and the Windows Task Scheduler.

    Response to edit: Of course you can use Windows Task Scheduler for this. The only function of the scheduler is to execute a task. There are no rules as to the complexity of the task it executes. Plus, querying a DB and sending an email isn't exactly an overly complex task. :)