后台任务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 全栈开发,Day36(作业讲解(大文件下载以及进度条展示),socket的更多方法介绍,验证客户端链接的合法性hmac,socketserver)
先来回顾一下昨天的内容 黏包现象粘包现象的成因 : tcp协议的特点 面向流的 为了保证可靠传输 所以有很多优化的机制 无边界 所有在连接建立的基础上传递的数据之间没有界限 收发消息很有可能不完全相 ...
- [HEOI2016/TJOI2016]序列
题解: 很水的题目 首先容易发现每个位置实际上只有最大值是有用的 然后把条件变成dp[i]=max(dp[j]+1)(j<i,F[i]>G[j],G[i]>H[j]) 然后我研究了一 ...
- [HAOI2016]放棋子
题解: 刚开始没有仔细看题目.. 后来发现障碍是每行每列有且只有一个 那么其实会发现这就是一道错排的题目 f[i]=(n-1)*(f[i-1]+f[i-2])
- asp.net core配置访问地址
配置Kestrel Urls有四种方式,我这里只介绍一种.其它方式可自行百度. 在Program.cs里使用UseUrls()扩展方法进行设置.UseUrls()方法的参数是个字符串数组,可以同时设置 ...
- BZOJ1968 [Ahoi2005]COMMON 约数研究 数论
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1968 题意概括 求 ΣF(i) (1<=i<=n)N<=1000000 F( ...
- Adobe Acrobat Pro DC破解
下载amtemu 点击 在AMT Emulator界面,下拉选择Adobe Acrobat DC; 然后点击右下角Install安装破解补丁. 点击Install后在弹出窗口中手动找到并选择软件安装目 ...
- Linux 内核的定时机制实验
参考链接: Linux struct itimerval用法: http://blog.csdn.net/hbuxiaofei/article/details/35569229 Linux定时器实验: ...
- with 重写enter exit 方法
- POJ 2407 Relatives【欧拉函数】
<题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relativel ...
- wireshark实战之局域网抓包分析
Wireshark.它是一款本地监听数据的大杀器,弊端是只能监听本地的数据,有什么办法可以让局域网中的流量都从本机走呢? 第一ARP嗅探,劫持网关,再本地抓包. 第二交换机镜像端口,在路由或者交换机处 ...