0

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

gideon
  • 19,329
  • 11
  • 72
  • 113
santhosh
  • 1
  • 1
  • 1
  • See this related/similar Q : http://stackoverflow.com/questions/850556/how-to-emulate-cron-jobs-on-a-windows-server – gideon Feb 28 '11 at 17:01
  • Another very similar Q : http://stackoverflow.com/questions/4559978/asp-net-script-in-task-scheduler – gideon Feb 28 '11 at 17:06

3 Answers3

2

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.

Jimmy Chandra
  • 6,472
  • 4
  • 26
  • 38
2

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.

DuckMaestro
  • 15,232
  • 11
  • 67
  • 85
1

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.

Richard B
  • 1,581
  • 1
  • 15
  • 31