后台任务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 ...
随机推荐
- springMVC3学习--ModelAndView对象(转)
原文链接:springMVC3学习(二)--ModelAndView对象 当控制器处理完请求时,通常会将包含视图名称或视图对象以及一些模型属性的ModelAndView对象返回到DispatcherS ...
- Ext.js入门:TreePanel(九)
一:最简单的树 二:通过TreeNode自定义静态树 三:用TreeLoader加载数据生成树 四:解决IE下非正常加载节点问题 五:使用TreeNodeUI 六:带有checkbox的树 七:编辑树 ...
- mac和Linux的环境变量设置
摘抄自:http://hi.baidu.com/machao_pe/item/763d0ef12d32cd35fe3582db redhat和ubuntu中修改环境变量 2010-03-06 23:4 ...
- Python yaml模块
引用自:https://www.cnblogs.com/shaosks/p/7344771.html 一.简介 YAML 语言(发音 /ˈjæməl/ )的设计目标,就是方便人类读写.它实质上是一种通 ...
- Vijos1910 NOIP2014提高组 Day2T3 解方程 其他
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - Vijos1910 题意概括 已知多项式方程: a0+a1x+a2x2+...+anxn=0 求这个方程在[1 ...
- P3144 关闭农场 并查集 反向
FJ和他的奶牛们正在计划离开小镇做一次长的旅行,同时FJ想临时地关掉他的农场以节省一些金钱. 这个农场一共有被用M条双向道路连接的N个谷仓(1<=N,M<=3000).为了关闭整个农场,F ...
- Centos7 安装pyquery 等包的简易方法
单独下载安装模块: sudo mkdir /home/pythonmodule sudo wget https://www.crummy.com/software/BeautifulSoup/bs ...
- AFP溢出攻击模块afp/loginext
AFP溢出攻击模块afp/loginext 在苹果Mac OS X 10.3.3及以前版本,AFP服务存在缓存区溢出漏洞CVE-2004-0430.利用该漏洞,用户可以基于LoginExt包执行任 ...
- 在webpack中使用postcss之插件cssnext
学习了precss插件包在webpack中的用法后,下面介绍postcss的另一个重要插件cssnext,步骤没有precss用法详细,主要介绍css4的语法,cssnext目前支持了部分新特性,你可 ...
- android monitor 汉化
作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱:313134555@qq.com E-mail: 313134555 @qq.com === == ============= = ...