Home > Net >  How can I create a recurrent tasks in .Net
How can I create a recurrent tasks in .Net

Time:12-14

For one of my project, I need to create a task that updates the status of cars when they are late. They are considered late when they exceed their schedule time.

So, I would like to know what is the best solution to do this.

Should I create a job that run every minute ? Or are there better solution that are less resources expensive ?

CodePudding user response:

Considering the question, one of the solutions could be to use a scheduler like Quartz.net (https://www.quartz-scheduler.net/).

You did not present a lot of detail on the problem itself, so i am assuming that you are doing something like lending the car for someone and they have a time limit.

Since that information was not provided, there are a lot of scenarios. Do you really need a scheduler? Do you want to know if they are late when they are delivered/arrive? If so, you probably just need to calculate whenever the delivery/action you are expecting happens.

But, if you really need a scheduler to trigger something, you can use a scheduler.

Quartz.net can be in memory (good for POC purposes: https://www.quartz-scheduler.net/documentation/quartz-1.x/tutorial/job-stores.html#ramjobstore), but also in database (so you can share with multiple instances of the same service https://www.quartz-scheduler.net/documentation/quartz-1.x/tutorial/job-stores.html#ado-net-job-store-adojobstore).

You can simply have a job that has arguments (such as the car id), and then reuse the same code. The jobs can be scheduled in several ways, simply datetime (https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/simpletriggers.html#simple-triggers), or even be recurrent with cron expressions (https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontriggers.html#example-cron-expressions).

There are other schedulers available, but Quartz.Net was the one i already used in several scenarios, both professionally and personally

  • Related