Recommend a simple, lightweight, powerful c#/asp. NET Timer Task Execution Manager component –fluentscheduler

Source: Internet
Author: User

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:

using fluentscheduler; public class myregistry : Registry {Public myregistry()     { //Schedule an ITask -to-run at an interval Schedule<mytask>(). Torunnow(). Andevery(2). Seconds(); //Schedule an ITask to run once, delayed by a specific time interval. Schedule<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< Span class= "Crayon-sy". now) ) .torunevery (1) days (.at (2115 //Schedule a more complex action to run immediately and on an monthly interval Schedule(() =>         { Console. WriteLine("Complex Action Task starts:" + DateTime. ) Now); Thread. Sleep(+); Console. WriteLine("Complex Action Task Ends:" + DateTime. ) Now); } . Torunnow (. Andevery (1) .< Span class= "CRAYON-E" >months (.onthefirst (dayofweek.< Span class= "crayon-v" >monday) . At (3, 0 //schedule Multiple tasks to being run in a single Schedule        Schedule<mytask> (. Andthen<myothertask> (. Torunnow (. Andevery (5) .< Span class= "CRAYON-E" >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 Myregistry ());
}

More applications need to be self-operating, not listed here.

Recommend a simple, lightweight, powerful c#/asp. NET Timer Task Execution Manager component –fluentscheduler

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.