using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hangfire
{
class Program
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static void Main(string[] args)
{
GlobalConfiguration.Configuration
.UseLog4NetLogProvider()
.UseSqlServerStorage("Data Source=localhost;User Id=sa;Password=123456;Database=DataSample;Pooling=true;Max Pool Size=5000;Min Pool Size=0;");
Console.WriteLine("Hangfire Server started. Press any key to exit...");
var server = new BackgroundJobServer();
//支持基于队列的任务处理:任务执行不是同步的,而是放到一个持久化队列中,以便马上把请求控制权返回给调用者。
var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("{0}===》这是队列任务!", DateTime.Now.ToString("HH:mm:ss")));
//延迟任务执行:不是马上调用方法,而是设定一个未来时间点再来执行。
BackgroundJob.Schedule(() => Console.WriteLine("{0}===》这是延时任务!", DateTime.Now.ToString("HH:mm:ss")), TimeSpan.FromSe
HangFire任务调度实例(Console和MVC中)及Log4Net日志配置
最新推荐文章于 2025-02-06 20:18:13 发布