[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

Creating Scheduled Tasks (.NET)

I'm looking for an efficent way to run dynamically created scheduled tasks e.g. I want a website user to define a date/time to run a job.

At the moment Im using windows services to repeatedly hit a db until the time matches - however this seem very in efficient - is there a better way to do this?

For the record I have access to SQL 2005 but this isn't necessary however Id like to develop this in vb.net 2005

Thanks in advance
  • 2
  • 2
1 Solution
Some details might help.
1. Can more than one user schedule a task (at different times or the same time) for a service?
2. If you are currently writing information about the scheduled task to the DB, would you continue to do so if the service did not need to poll the DB?
3. How time-critical are the tasks? For example, do they need to run to the neares ms, minute, hour, ect?

Windows services is the best solution.
What I'd recomment is that you make an array (read from db once) holding the next 10 minutes of SHTasks
When fineshed the 10 minutes, then you read the next Shceduled 10 minutes.

Now in the mean time (inbetween the 10 minutes) some user might add a task to the db and the task was ment to run in the inbetween time frame.
If this is not critical, then you will run the task from 1-10 minutes later.
If it is critical, you may modify your website code to check the to alert your windows service, with something like a .txt file that you may read each time (within the 10 minutes) and see if something has to run again.

Now if you want the exact time to match the Shedule, what you are doing now is the best. Hit the db every second
paulCardiffAuthor Commented:
Hi Jim
1) Yes more than one user can
2) Yes i would hit the db
3) Nearest Minute would be best way a explaining?
paulCardiffAuthor Commented:
Hi AkisC:
I agree this is an option but essentially i'm still hitting the db time and time again only at larger intervals -  thsi is something i've considered already but i'm curious if theres a better way e.g.

Tapping into windows scheduler
or using service broker

But so far this is my best option - though i'll be honest not my favourite :-)
Hi paulCardiff
1) -windows scheduler=saves/loads jobs from a database... -service broker =the same

2) ASP.NET was not designed to do any shceduled tasks, so the only you can do from a website is to insert-edit-delete a job you want to/from a database.
2.1) Now you have to load the job in memory, as windows scheduler does.
2.1.1) Shedule tasks are loaded into memory from a database created when you add a job.
When you add a Shedule task from the Shedule tasks inteface, it can be loaded in memory at the same time because you use the SHTask inteface. --From asp.net there is not such an option

3) Lot's of Windows services are running all the time in your computer, doing some kind of a job. They open a kind of database and check what must be done, when and so on..., so the best think you have to do is what you have already done.  A windowes service!  It runs in the background, separete tread and if your computer has ram, you should face no impact with performance.

4) I'd recomment a 30 minute interval of getting the info from your database and strore jobs to be done in an array
-Also- modify your .aspx code and when a new job is inserted then open a .txt file writting new job in
-from- your windows service check on a timer 1 sec if the .txt file exists. If it exists then read info and ajust your array if a job is inbetwwen these 30 minutes otherwise ignore it and delete the file.
That way you will not face any problem with performance.

Windows services are my favourite ;-)
Have fun codeing...

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now