Timer to cast method once a week - C #, Asp.NET

I am new to C # and coding in general. I am looking for an example / open source timer function that will be used to drop a basic method (e.g. email notifications) once a week at a specific time. After some research, I found that using a timer instead of a Windows service would be wise, as it would have a very small workload.

I found an API with several timers in CodePlex and Code Project, but I had problems working with examples due to my minimal knowledge of C #.

Does anyone know about a simple timer that I could use, is it newbie friendly and that also passed? Or is there an easier way to do this using System.Timers?

My ultimate goal is to have a timer that will start the method at 8:00 AM every Monday.

EDITOR: I believe that I should have been more detailed in my original Post. The reason I decided not to use the Windows Task Scheduler is because the method I'm calling is more complicated than just calling the Windows Task.

When the timer reaches the scheduled time, it starts a method that queries the database for items requiring maintenance for a certain period of time. Then, items that add them to the email that will be sent to this warehouse administrator will be cyclically moved.

If I'm not mistaken, is it impossible to do this using the Windows Task Scheduler?

+4
source share
5 answers

Using a timer for this does not make sense. Your goal is to fire a function at a specific time. What if your server restarts? Will your timer calculate the exact time between the reset time and Monday at 8:00 in the morning?

IMO, use the console application and the Windows task scheduler.

Reply to edit . Of course, you can use the Windows task scheduler for this. The only function of the scheduler is to complete the task. There are no rules regarding the complexity of the task. In addition, querying the database and sending email is not too difficult. :)

+8
source

I am using Quartz.NET for cron jobs. It also works on a hosted platform where you do not have access to Windows services.

What you are looking for would be trivial to achieve. Take a look at the first example from tutorial .

http://quartznet.sourceforge.net/tutorial/lesson_1.html

+2
source

I would not agree with your research and put it in a console application that was launched by Windows Scheduler.

+1
source

Since you're pretty new to coding, the simplest thing you need to do is create an application (the c # console application is best) and use

Task Scheduler

which is built into Windows to run the application at 8:00 a.m. every Monday.

0
source

A cron task would be a much better option. What happens if your website is on Monday morning at 8am? Using cron, while the server is running, it can fulfill your request.

0
source

Source: https://habr.com/ru/post/1341684/


All Articles