In C#winform or ASP. NET Web applications, depending on the needs of the various timing tasks, such as: daily data statistics, hourly refresh system cache and so on, this time we have to apply to the timer this stuff.
The. NET framework has a timer that comes with it, but this class can only do some simple timing operations, such as what to do at intervals. It is relatively difficult for the timer class to deal with complex timed tasks, such as starting at the current time and repeating the interval after a few hours. After many searches, finally found a more useful task timer –fluentscheduler, you can use NuGet to reference, with the package Manager to execute the following command to install:
Install-package Fluentscheduler
This component can be used in C # and ASP. The use of the method is simple, the official use case:
usingFluentscheduler; Public classmyregistry:registry{ PublicMyregistry () {//Schedule an ITask -to-run at an intervalSchedule<mytask> (). Torunnow (). Andevery (2). Seconds (); //Schedule an ITask to run once, delayed by a specific time intervalSchedule<mytask> (). Torunoncein (5). Seconds (); //Schedule A simple task to run at a specific timeSchedule (() = Console.WriteLine ("Timed Task-will run every day at 9:15pm:"+DateTime.Now)). Torunevery (1). Days (). at ( +, the); //Schedule a more complex action to run immediately and on an monthly intervalSchedule (() ={Console.WriteLine ("Complex Action Task starts:"+DateTime.Now); Thread.Sleep ( +); Console.WriteLine ("Complex Action Task Ends:"+DateTime.Now); }). Torunnow (). Andevery (1). Months (). Onthefirst (Dayofweek.monday). at (3,0); //Schedule Multiple Tasks to being run in a single ScheduleSchedule<mytask> (). Andthen<myothertask> (). Torunnow (). Andevery (5). Minutes (); }}
In the Global.asax file of the ASP. NET program, first initialize the manager so that the timer is turned on.
protected void Application_Start () { taskmanager.initialize (New
More applications need to be self-operating, not listed here.
[GO] Recommend a simple, lightweight, powerful c#/asp. NET Timer Task Execution Manager component –fluentscheduler