标签:init body 添加 请求 schedule www. date ora 表达式
开发环境:VS2017,SQL Server 2012,.NET Framework 4.5
PM>Install-Package Hangfire
GlobalConfiguration.Configuration.UseColouredConsoleLogProvider().UseSqlServerStorage("Data Source=127.0.0.1;User ID=sa;Password=XXXX;Initial Catalog=Hangfire;Connection Reset=False;");
任务类别 | 任务描述 | 基本语法 |
Fire-and-forget | 将当前任务放入到一个持久化的队列中,以便程序可以继续执行 | BackgroundJob.Enqueue |
Delayed | 任务在未来的一个时间点执行 | BackgroundJob.Schedule |
Recurring | 可重复执行的任务 | RecurringJob.AddOrUpdate |
Continuations | 将多个任务连接成类似工作流的形式顺序执行 | BackgroundJob.ContinueWith |
using (var server = new BackgroundJobServer()) {//支持基于队列的任务处理:任务执行不是同步的,而是放到一个持久化队列中,以便马上把请求控制权返回给调用者BackgroundJob.Enqueue(() => Console.WriteLine("Simple111"));//延迟任务执行:不是马上调用方法,而是设定一个未来时间点再来执行。BackgroundJob.Schedule(() => Console.WriteLine("Reliable!"), TimeSpan.FromSeconds(5));//一行代码添加重复执行的任务,其内置了常见的时间循环模式,也可基于CRON表达式来设定复杂的模式。RecurringJob.AddOrUpdate(() => Console.WriteLine("Transparent!"), Cron.Minutely);//Continuations: Continuations allow you to define complex workflows by chaining multiple background jobs together.var jobId = BackgroundJob.Enqueue(() => Test("========First job"));BackgroundJob.ContinueWith(jobId, () => Test("========Start execute next task"));Console.WriteLine("Hangfire Server started.Press any key to exit");Console.ReadKey();}
标签:init body 添加 请求 schedule www. date ora 表达式
原文地址:http://www.cnblogs.com/lightmao/p/7254197.html