santhosh
santhosh

Reputation: 1

how to create and run cron job in asp.net page to run every 30 minutes

I need some guidance on creating and running a Cron Job in asp.net(C#.net) to run my page every 30 minutes. My Web page has to load data from Sql Server to MySql database every 30 minutes with this cron job.

Thanks

Upvotes: 0

Views: 5644

Answers (3)

Richard B
Richard B

Reputation: 1581

Try investigating quartz.net, which is an open source port of the quartz project. I believe you should be able to include it as part of your web application.

Upvotes: 1

DuckMaestro
DuckMaestro

Reputation: 15885

I don't think you'll find that feature out-of-the-box in ASP.NET. Here's what I usually do...

  1. Setup a database table to track jobs, including the last time that each job ran.
  2. In Global.asax's Application_Start event, I spin up a new .NET Thread, which runs a job checking loop.
  3. In this loop, check your known jobs, check the database for the last run time, and then decide if it's time to run the job again. Run the job, update the database.
  4. Sleep the thread for a bit. Continue the loop.
  5. Be aware of the what-if's.
    1. What if a task fails in your job loop, throwing an exception.
    2. What if your in a server farm, and need to prevent multiple application instances from running the same task at the same time.

This is just something to get you started. Making this robust (if you need it robust) can get complicated.

Upvotes: 2

Jimmy Chandra
Jimmy Chandra

Reputation: 6580

I don't think this is best suited for ASP.NET. You might want to just create a regular Console App, configure it in the Server Task Scheduler to run every 30 minutes. Or if you so inclined, you can create your own Windows Service to do this.

Upvotes: 2

Related Questions