分享幾個.NET 下的計劃工作群組件

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   使用   sp   

Quartz

http://www.quartz-scheduler.net/(現項目在使用,可以看我之前的文章)

Hangfire

http://hangfire.io/

FluentScheduler

https://github.com/jgeurts/FluentScheduler
Nuget :Install-Package FluentScheduler
使用很簡單,一直直接使用TaskManager類管理即可

using System;using System.Collections.Generic;using System.Linq;using System.Text;using FluentScheduler;namespace TestFluentScheduler{  class Program  {    static void Main(string[] args)    {      TaskManager.AddTask(() =>      {        //Do something...        Console.WriteLine("Timer task,current time:{0}", DateTime.Now);      }, t =>      {        //每5秒鐘執行一次        t.ToRunNow().AndEvery(5).Seconds();        ////帶有任務名稱的任務定時器        //t.WithName("TaskName").ToRunOnceAt(DateTime.Now.AddSeconds(5));      });      Console.ReadKey();    }  }}

使用繼承FluentScheduler的Registry類(需要初始化)

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 time        Schedule(() => Console.WriteLine("Timed Task - Will run every day at 9:15pm: " + DateTime.Now)).ToRunEvery(1).Days().At(21, 15);        // Schedule a more complex action to run immediately and on an monthly interval        Schedule(() =>        {            Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);            Thread.Sleep(1000);            Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);        }).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);        //Schedule multiple tasks to be run in a single schedule        Schedule<MyTask>().AndThen<MyOtherTask>().ToRunNow().AndEvery(5).Minutes();    }}

在web程式的Global.asax檔案中初始化

protected void Application_Start(){    TaskManager.Initialize(new MyRegistry()); }

WebBackgrounder

http://www.nuget.org/packages/WebBackgrounder/
http://diaosbook.com/Post/2014/7/18/how-to-run-schedule-jobs-in-aspnet

Taskschedulerengine

http://taskschedulerengine.codeplex.com/

分享幾個.NET 下的計劃工作群組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.