abp版本6.0.3
使用abp后台工作者而不是后台作业
以下为步骤:
1.在解决方案力新建一个XXXQuartz的项目
2.nuget安装AbpBackgroundWorkersQuartzModule
3.新建一个XXXQuartzModule.cs文件
using Volo.Abp.BackgroundWorkers.Quartz; using Volo.Abp.Modularity; namespace XXX.Quartz { [DependsOn(typeof(AbpBackgroundWorkersQuartzModule))] public class XXXQuartzModule : AbpModule { } }
4.新建一个Worker的文件夹
5.新建一个TestWorker.cs文件
//Copyright(c) Microsoft.All Rights Reserved. using Microsoft.Extensions.Logging; using Quartz; using Volo.Abp.BackgroundWorkers.Quartz; namespace XXX.Quartz.Worker { public class TestWorker : QuartzBackgroundWorkerBase { public TestWorker() { //测试 使用corn表达式每分钟执行一次 JobDetail = JobBuilder.Create<TestWorker>().WithIdentity(nameof(TestWorker)).Build(); Trigger = TriggerBuilder.Create() .WithIdentity(nameof(TestWorker)) .WithCronSchedule("0 * * * * ?").Build(); ScheduleJob = async scheduler => { if (!await scheduler.CheckExists(JobDetail.Key)) { await scheduler.ScheduleJob(JobDetail, Trigger); } }; } public override Task Execute(IJobExecutionContext context) { Logger.LogInformation("Executed TestWorker..!"); return Task.CompletedTask; } } }
6.最后在XXXApplication项目里的XXXApplicationModule .cs文件中的DependsOn中添加
typeof(XXXQuartzModule)
大功告成
标签:Abp,Quartz,abp,任务,TestWorker,using,定时,public From: https://www.cnblogs.com/0banana0/p/17635408.html