I would like to know if there is a way to schedule a job to be run when something expires(reaches specific datetime). In the application that I am building for one of the things that I need this is for a functionality that is allowing users to open specific advertisements and beside the content of the advertisement they are putting the datetime the advertisement will expire. I would like to know if there is a way to add a scheduling job when the advertisement is created and to be executed when the datetime is reached and only then, not periodically. This new scheduling job is only for that advertisement. So there are as many scheduling jobs as there are active advertisement. When the scheduling job executes it is removed because it will be no longer needed. I have found one solution which is not perfect and involves using timers that are ran periodically every fixed minutes and checks if some of the advertisements datetimes expired and take the appropriate action. Thank you.
Asked
Active
Viewed 317 times
2 Answers
1
You can use hangfire for that RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Daily);
It is easy integrate with asp.net and moreover all tasks will execute outside of iis thread pool
http://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html

Ilya Sulimanov
- 7,636
- 6
- 47
- 68
0
Why not use the Windows Scheduler ? You can create schedule jobs from .net quite easily.
I have to say that your solution design is very unusual - its more normal to have a single polling schedule which looks at a table/store of activities, and executes those activities when their execution date/time is reached. Creating a schedule for each separate activity is not going to scale very well.

PhillipH
- 6,182
- 1
- 15
- 25
-
Thank you for your reply. I was somewhere between using one job to run periodically and update the needed data or jobs for every instance of data to be ran only once. I will take your advice and choose the periodical approach. Can you give me some pointers on how to do that with the Windows Scheduler. To have a single polling schedule with a table of activities. Can this table be part of the database? I am sorry for my lack of experience but I am doing this scheduling implementation for the first time. – Strelecxii Aug 19 '16 at 14:34
-
Try too google around ".net create windows schedule job" and you will find this very helpful code snippet right here on StackOverflow. http://stackoverflow.com/questions/7394806/creating-scheduled-tasks. Its beyond the scope of your original question to ask for help designing a scheduling database - however, why not just store your job schedule in a simple text file, and read it in the job that is executed by the Windows Scheduler. Alternatively there are many .net scheduling frameworks out there - for instance Quartz.net. – PhillipH Aug 27 '16 at 21:20