FluentScheduler timed task library, by nuget reference, you can set various event interval ,, super convenient and simple.
FluentScheduler example timer
the using FluentScheduler; the using the System; the using the System.Collections.Generic; the using the System.Linq; the using the System.Text; the using System.Threading.Tasks; namespace NetFrameTest.test { public class MyRegistry: Registry { public MyRegistry () { // perform daily. once (this is carried out every day in the afternoon 15:40 minutes), you can not type, direct virtual method Schedule (() => Console.WriteLine ( " It's 15:42 now. " )). ToRunEvery ( 1 ) .Days ( ) .AT ( 15 , 42 is ); //Executed once every two seconds (to specify a time interval to run, according to their own needs, can be seconds, minutes, hours, days, months, years and so on.) Schedule <MyJob> (). ToRunNow (). AndEvery ( 2 ) .Seconds ( ); // every five seconds execution time (delay a specified time interval to perform a scheduled task) . Schedule <MyJob> () ToRunOnceIn ( 5 ) .Seconds (); // perform once a month (the first month here in Monday at 3:00 perform) the Schedule <MyJob> () ToRunNow () AndEvery (.. . 1 ) .Months () OnTheLast (DayOfWeek.Friday) .AT (. 16 , 0 ); // constructor executes the Schedule (( ) => new new MyOtherJob ( " Foo " .)) ToRunNow () AndEvery (. 2 ) .Seconds (); // execute two (multiple) tasks in the same plan Schedule<MyJob>().AndThen<MyOtherJob>().ToRunNow().AndEvery(5).Minutes(); } } public class MyJob : IJob { public void Execute() { Console.WriteLine($"MyJob 当前时间:{DateTime.Now}"); } } public class MyOtherJob : IJob { private string Name; public MyOtherJob(string name) { Name = name; } public void the Execute () { Console.WriteLine ($ " MyOtherJob Name: {Name} Current time: the DateTime.Now {} " ); } } }
Written after the regular tasks only need to refer to it in the Main
// static void Main(string[] args) JobManager.Initialize(new MyRegistry());