后台任务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 ...
随机推荐
- python 全栈开发,Day82(点赞和踩灭,用户评论)
一.点赞和踩灭 样式 先来做样式,修改article_detail.html,增加div_digg的div {% extends "base.html" %} {% block c ...
- POJ 2010 Moo University - Financial Aid (优先队列)
题意:从C头奶牛中招收N(奇数)头.它们分别得分score_i,需要资助学费aid_i.希望新生所需资助不超过F,同时得分中位数最高.求此中位数. 思路: 先将奶牛排序,考虑每个奶牛作为中位数时,比它 ...
- vtiger自定上传图片的字段
废话不多说,上一篇有说到过vtiger新建模块的事 现在我新建了一个Score的模块,里面需要一个上传图片的功能 在Score界面新建一个字段叫grede 但是自定义类型里面是没有,图片这个选项的,只 ...
- Jmeter如何提取响应头部的JSESSIONID
近期有柠檬班的学生找到华华,问了一个问题,就是利用Jmeter做接口测试的时候,如何提取头部的JSESSIONID然后传递到下一个请求,继续完成当前用户的请求. 其实,关于这个问题有三种种解决方法: ...
- BZOJ1191 [HNOI2006]超级英雄Hero 二分图匹配
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1191 题目概括 有m个题目,有n个解决方案:对于每一个题目,有两种解决方案可用. 每种解决方案只能 ...
- jupyter notebook connecting to kernel problem
前几天帮同学配置 python 和 anaconda 环境,在装 jupyter notebook 时,出了点问题,搞了一天半终于搞好了,也是在 github 里找到了这个问题的解答. 当时显示的是无 ...
- 【Java并发核心五】Future 和 Callable
默认情况下,线程Thread对象不具有返回值的功能,如果在需要取得返回值的情况下会极为不方便.jdk1.5中可以使用Future 和 Callable 来获取线程返回值. Callable 可以 看成 ...
- scikit-learn全局图
https://scikit-learn.org/stable/tutorial/machine_learning_map/index.html
- POJ.1830.开关问题(高斯消元 异或方程组)
题目链接 显然我们需要使每个i满足\[( ∑_{j} X[j]*A[i][j] ) mod\ 2 = B[i]\] 求这个方程自由元Xi的个数ans,那么方案数便是\(2^{ans}\) %2可以用^ ...
- java生成一次性验证码
1.编写生成验证码的工具类: import java.awt.BasicStroke;import java.awt.Color;import java.awt.Font;import java.aw ...