3

I have a simple question to ask.. Does anyone know how to create a repetitive scheduler in ASP.NET MVC 4. What I'm attempting to build is an Irrigation System that I can set the days of the week and times for my system to activate each week. So the user would select the Day of the week along with the time and duration the system should run. How do I keep a running clock that triggers the system to turn on?.. Should I use a drop down list for my properties? Although it would be nice, I'm not asking for you to write an entire application for me.. A simple point in the right direction would help tremendously.. The problem with searching for the answers over the net is I really don't know what to search for.

Thank you in advance..

Digbyswift
  • 10,310
  • 4
  • 38
  • 66
digiShadoe
  • 117
  • 5
  • 15
  • 1
    http://haacked.com/archive/2011/10/16/the-dangers-of-implementing-recurring-background-tasks-in-asp-net.aspx – ta.speot.is Sep 19 '13 at 05:30
  • you might a windows scheduled task to run the process .. you can create a windows scheduled task programmaticly using this http://taskscheduler.codeplex.com/ – Dhaval Sep 19 '13 at 05:38

4 Answers4

9

We are using Quartz.Net exactly for this. It is a port of Quartz for Java.

It is very powerful and it is quite easy to define new jobs (what should be done) and schedules (when to do it). The new versions support a Cron scheduler which supports linux cron like configuration - so it is quite easy to start a job on every monday, or on every 5th of the month or for every 5 minutes on a given date. I think it's hard for scheduled tasks to beat this flexibility.

We are using the database configuration and a service on the server (this is the "running clock which activates things). Additionally a web services is used to configure the Quartz scheduler and the running service is changed through the database (this is done by Quartz.Net for you). All these things are supported nicely with it.

Some tips to start with cron triggers:

First thing would be the tutorial from http://quartznet.sourceforge.net/tutorial/lesson_1.html . Lessons 1 - 3 show you the basic building blocks. Lesson 9 shows you the ADO job store (for db persistance).

Working with the cron trigger would work like this

ITrigger trigger = TriggerBuilder.Create().WithIdentity(id).StartNow().WithCronSchedule(cronstring).Build();
scheduler.ScheduleJob(job, trigger);

To give you an idea of the possibilites of the cron trigger this guide comes handy.

bernhardrusch
  • 11,670
  • 12
  • 48
  • 59
  • I also use Quartz from a Windows service. Its versatility and it's different Triggers make it really easy to schedule tasks. – Carles Company Sep 19 '13 at 06:13
  • After reading through the documentation this is probably the answer I've been looking for. Do you know of any video or walk through tutorials associated with Quarz.net using cron configurations in asp.net? Thanks for your help, tremendously! – digiShadoe Sep 19 '13 at 17:38
  • I've updated the question to show you some tips to get started – bernhardrusch Sep 20 '13 at 05:59
3

Friend, you can create a scheduler with the help of following code

void Application_Start(object sender, EventArgs e)
{
    System.Threading.Timer _timer = new System.Threading.Timer(
                                           new TimerCallback(GetProducts));

    _timer.Change(0, 51000); // here you can change the start time  interval
}


static void GetProducts(Object state)
{
    // do something
}
Digbyswift
  • 10,310
  • 4
  • 38
  • 66
DK Chauhan
  • 194
  • 1
  • 11
2

To make scheduled tasks on an independent date time server, and get detailed reports about all tasks, you can use A Trigger as a scheduling service. abilities such as pause, resume or delete sets of tasks using tags, archiving and storing all call results such as possible errors will really help developers independent of the programming language.

.Net library is also available:

//Create
ATrigger.Client.doCreate(TimeQuantity.Day(), "1", "http://www.example.com/myTask?something", tags);

Disclaimer: I was amoung ATrigger builders. It's an absolutely freeware, not commercial purpose.