标签:NETCORE app TimeJob System method cs using 定时 public
引用网址:https://www.cnblogs.com/1285026182YUAN/p/12930687.html
NETCORE - TimeJob定时任务的使用
1. 安装 nuget 包
Install-Package Pomelo.AspNetCore.TimedJob -Pre
2. startup.cs
Start.cs的ConfigureServices注入AddTimedJob服务
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddTimedJob(); }
Start.cs的Configure引入UseTimedJob中间件
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseTimedJob(); app.UseHttpsRedirection(); app.UseMvc(); }
3. 使用
新建 JobTest.cs 类 继承Job。
using Pomelo.AspNetCore.TimedJob; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace NETCORE.TimeJob.JobClass { public class JobTest : Job { //Begin:开始时间 Interval:间隔(毫秒,建议写成1000*60*60 格式) SkipWhileExecuting:是否等待上一个执行完成 [Invoke(Begin = "2018-07-27 00:00", Interval = 1000 , SkipWhileExecuting = true)] public void TestFun() { Console.WriteLine("my test job ~!"); } } }
标签:NETCORE,app,TimeJob,System,method,cs,using,定时,public 来源: https://www.cnblogs.com/bruce1992/p/15611517.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。