What is Fluentscheduler?
Automated job scheduler with fluent interface.
This is the author's introduction on Github, which is a timed task manager. Similar to Microsoft's Timer, Quartz.net, Fluentscheduler, and Windows services in. Net, there is little difference between the use of quartz.net and the Quartz under Java.
Timing tasks or job scheduling may also be useful when you specify a time to do statistics, send e-mails, or some business logic that you want to complete, which is what it's all about.
How do I use Fluentscheduler?
I recommend you go to the author's Github to see the source code or example, address: Https://github.com/fluentscheduler/FluentScheduler
Of course, here I use the author's example to do a demonstration and translation, to ensure that anyone can read.
First, install the FluentScheduler
package
Open the Package management console and enter Install-Package FluentScheduler
. Step: Status bar Selection Tool-Library Package Manager-Package management console, such as:
Input Install-Package FluentScheduler
.
Second, write code
I simply post the author's sample code, it is recommended that you go to Github to see, but I readily translated, it may be easier to read some.
Public classdemo:registry{ PublicDemo () {//Schedule an IJob -to-run at an interval//perform scheduled tasks once every two seconds immediately. (Specify a time interval to run, depending on your needs, can be seconds, minutes, hours, days, months, years, and so on.) )Schedule<myjob> (). Torunnow (). Andevery (2). Seconds (); //Schedule an IJob to run once, delayed by a specific time interval//delays the execution of a scheduled task at a specified time interval. (Of course, this interval can still be seconds, minutes, hours, days, months, years, etc.) )Schedule<myjob> (). Torunoncein (5). Seconds (); //Schedule A simple job -to-run at a specific time//perform scheduled tasks at a specified time (most commonly used. This is done at 1:10 every day)Schedule (() = Trace.WriteLine ("It ' s 1:10 PM now.")). Torunevery (1). Days (). at ( -,Ten); Schedule (()= { //do what you want to do. Trace.WriteLine ("It ' s 1:10 PM now."); }). Torunevery (1). Days (). at ( -,Ten); //Schedule a more complex action to run immediately and on an monthly interval//immediately perform a scheduled task at the month of Monday 3:00 (it can be seen that this is a more complicated point of time, it means it can do it too!) )Schedule<mycomplexjob> (). Torunnow (). Andevery (1). Months (). Onthefirst (Dayofweek.monday). at (3,0); //Schedule multiple jobs to being run in a single Schedule//perform two (multiple) tasks in the same planSchedule<myjob> (). Andthen<myotherjob> (). Torunnow (). Andevery (5). Minutes (); } } Public classmyjob:ijob{voidIjob.execute () {Trace.WriteLine ("now the time is:"+DateTime.Now); }} Public classmyotherjob:ijob{voidIjob.execute () {Trace.WriteLine ("This is another Job, and now the time is:"+DateTime.Now); }} Public classmycomplexjob:ijob{voidIjob.execute () {Trace.WriteLine ("This is a more complex Job, and the time is now:"+DateTime.Now); }}
Third, initialize
Global.asax
add a sentence in the
Jobmanager.initialize (new Demo ());
The above is simple to use, actually enough, of course, there are more perverted needs, the author also wrote in the document, such as this: you want to perform a scheduled task, every Monday 14:00 run. But it's Monday 10:00, so should your program run today or next Monday? It's used here ToRunEvery
.
There is also the processing of concurrent tasks, interested can go to see.
Summarize
Fluentscheduler is a. Net, you can easily implement scheduled tasks of the tool, do not need to write Windows services, more importantly, the time is set up a lot of flexibility, timing task difficult is not so.
ASP. NET MVC uses Fluentscheduler timers to schedule tasks