What is the equivalent to cron jobs in ASP.NET?

In PHP we have cron jobs, where the hosting server automatically picks up and executes a task as per the schedule given.

What would be a good alternative to use for CRON jobs in ASP.NET? I’d like to use a Web service, but that will not work in a shared hosting environment. Any help would be appreciated, and please advise a way to do this specifically in a shared hosting environment.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Try Quartz.NET. It’s a decent .NET scheduler which supports CRON expressions, CRON triggers and various other means and methods to schedule tasks to be performed at certain times / intervals.

It even includes a basic Quartz.NET server (Windows Application) that might fit your needs.

Edit:

If you can’t run applications or windows services within your shared hosting then perhaps something like “Easy Background Tasks in ASP.NET” will do you? It simulates a Windows Service using HttpRuntime.Cache and removes the need for any external dependancies.

Method 2

This is absolutely a hack, but you can simulate a cron service using ASP.NET callbacks. Here is an example of how to do it.

Method 3

nCron is a .Net implementation of CRON using nCronTabs which are the exact same as cron scheduling

Method 4

Asp.Net and Web services are typically responsive. They wait and respond to requests. There are hacks to make them look like schedulers but the hacks are ugly beyond belief.

You could use a Windows Service.
Or write an executable and use the Windows Task Scheduler.

Method 5

Another option is to use hangfire which says about itself

An easy way to perform background processing in .NET and .NET Core applications. No Windows Service or separate process required.

Backed by persistent storage. Open and free for commercial use.

Requirements (as of November 2019) are

  • .NET Framework 4.5
  • Persistent storage, e.g. an SQL database where Hangfire will write 10 tables
  • Newtonsoft.Json library ≥ 5.0.1

Assuming that you have already some API project which runs as service, you can use hangfire within.

Disclaimer: I am not affiliated in any kind with hangfire, I will just be using it soon.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x