后台任务hangfire
Installation¶
There are a couple of packages for Hangfire available on NuGet. To install Hangfire into your ASP.NET application withSQL Server storage, type the following command into the Package Manager Console window:
PM> Install-Package Hangfire
Configuration¶
After installing the package, add or update the OWIN Startup class with the following lines:
using Hangfire; // ... public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseSqlServerStorage("<connection string or its name>"); app.UseHangfireDashboard();
app.UseHangfireServer();
}
Authorization configuration required
By default only local access is permitted to the Hangfire Dashboard. Dashboard authorization must be configured in order to allow remote access.
Then open the Hangfire Dashboard to test your configuration. Please, build the project and open the following URL in a browser:

Usage¶
Add a job…¶
Hangfire handles different types of background jobs, and all of them are invoked on a separate execution context.
Fire-and-forget¶
This is the main background job type, persistent message queues are used to handle it. Once you create a fire-and-forget job, it is saved to its queue ("default" by default, but multiple queues supported). The queue is listened by a couple of dedicated workers that fetch a job and perform it.
BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget"));
Delayed¶
If you want to delay the method invocation for a certain type, call the following method. After the given delay the job will be put to its queue and invoked as a regular fire-and-forget job.
BackgroundJob.Schedule(() => Console.WriteLine("Delayed"), TimeSpan.FromDays(1));
Recurring¶
To call a method on a recurrent basis (hourly, daily, etc), use the RecurringJob class. You are able to specify the schedule using CRON expressions to handle more complex scenarios.
RecurringJob.AddOrUpdate(() => Console.WriteLine("Daily Job"), Cron.Daily);
Continuations¶
Continuations allow you to define complex workflows by chaining multiple background jobs together.
var id = BackgroundJob.Enqueue(() => Console.WriteLine("Hello, "));
BackgroundJob.ContinueWith(id, () => Console.WriteLine("world!"));
http://docs.hangfire.io/en/latest/quick-start.html#installation
后台任务hangfire的更多相关文章
- ASP.NET Core开发-后台任务利器Hangfire使用
ASP.NET Core开发系列之后台任务利器Hangfire 使用. Hangfire 是一款强大的.NET开源后台任务利器,无需Windows服务/任务计划程序. 可以使用于ASP.NET 应用也 ...
- 执行后台任务的利器——Hangfire
今年1月31日,在微软的MVP 2015社区大讲堂上,我给大家分享了一个演讲:在ASP.NET应用中执行后台任务.其中介绍了三种技术的应用:QueueBackgroundWorkItem.Hangfi ...
- Core开发-后台任务利器Hangfire使用
Core开发-后台任务利器Hangfire使用 ASP.NET Core开发系列之后台任务利器Hangfire 使用. Hangfire 是一款强大的.NET开源后台任务利器,无需Windows服务/ ...
- .NET Core开源组件:后台任务利器之Hangfire
一.简述 Hangfire作为一款高人气且容易上手的分布式后台执行服务,支持多种数据库.在.net core的环境中,由Core自带的DI管理着生命周期,免去了在NF4.X环境中配置always ru ...
- mvc中使用Hangfire处理后台任务
考虑下如下代码,在数据保存后,需要发送邮件,发送邮件是个耗时的工作. 我们的目的是,数据保存成功后,就可以返回响应了,发送邮件不重要,不需要等待邮件发送成功 [HttpPost] public Act ...
- 执行后台任务的利器——Hangfire
Hangfire是一个开源且商业免费使用的工具函数库.可以让你非常容易地在ASP.NET应用(也可以不在ASP.NET应用)中执行多种类型的后台任务,而无需自行定制开发和管理基于Windows Ser ...
- 后台任务利器之Hangfire
后台任务利器之Hangfire 一.简述 Hangfire作为一款高人气且容易上手的分布式后台执行服务,支持多种数据库.在.net core的环境中,由Core自带的DI管理着生命周期,免去了在NF4 ...
- ASP.NET Core-组件-后台任务:Hangfire
ylbtech-ASP.NET Core-组件-后台任务:Hangfire Hangfire作为一款高人气且容易上手的分布式后台执行服务,支持多种数据库.在.net core的环境中,由Core自带的 ...
- .NET Core开源组件:后台任务利器之Hangfire 转载 https://www.cnblogs.com/chenug/p/6655636.html
.NET Core开源组件:后台任务利器之Hangfire 一.简述 Hangfire作为一款高人气且容易上手的分布式后台执行服务,支持多种数据库.在.net core的环境中,由Core自带的D ...
随机推荐
- this和super不能同时出现在构造方法中
package com.bjpowernode.t02inheritance.c09; /* * 使用super调用父类的构造方法 */public class TestSuper02 { publi ...
- CSS3:透明度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- canvas画多边形
<canvas id = "myCanvas" width = '500' height = '500'> Canvas画正多边形 </canvas>< ...
- python全栈开发day45-DOM操作、对象、定时器
一.昨日内容回顾 1.内置对象 Array String Date Math 2.DOM事件三要素:事件源.事件.事件驱动程序 事件源,事件,事件驱动程序 3.获取事件源的三种方式 var oDiv ...
- 【noip模拟赛4】找啊找啊找BF 拓扑排序
描述 sqybi上次找GF的工作十分不成功,于是依旧单身的他在光棍节前的某天突发奇想,要给自己找一个BF(这里指的是男性的好朋友……),这样既可以和人分享内心的压抑(路人甲:压抑还分享么……),也可以 ...
- 练习题|MySQL
MySQL主要内容: 1.数据库介绍.类型.特性2.MySQL数据库安装.连接.启动.停止3.表字段类型介绍.主键约束.表创建语句4.常用增删改查语句.分组.聚合5.外键管理.unique字段.表结构 ...
- 【Java】 剑指offer(36) 二叉搜索树与双向链表
本文参考自<剑指offer>一书,代码采用Java语言. 更多:<剑指Offer>Java实现合集 题目 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不 ...
- 020 $.each的使用
在工作中见到这个知识点,不是特别懂,就查了查资料,顺便整理一下 1.定义与用法 each() 方法规定为每个匹配元素规定运行的函数. 提示:返回 false 可用于及早停止循环. 语法 $(selec ...
- 013 MapReduce八股文的wordcount应用
一:Mapreduce编程模型 1.介绍 解决海量数据的计算问题. >map:映射 处理不同机器上的块的数据,一个map处理一个块. >reduce:汇总 将map的结果进行汇总合并 2. ...
- TextInputLayout输入框验证
<!-- 通过修改<color name="colorAccent">#023cfa</color>可以修改正确提示文本的颜色 添加<item ...