.Net Core 定时任务TimeJob
轉(zhuǎn)載自:https://blog.csdn.net/u013711462/article/details/53449799
定時任務(wù)?Pomelo.AspNetCore.TimedJob
Pomelo.AspNetCore.TimedJob是一個.NET Core實(shí)現(xiàn)的定時任務(wù)job庫,支持毫秒級定時任務(wù)、從數(shù)據(jù)庫讀取定時配置、同步異步定時任務(wù)等功能。
由.NET Core社區(qū)大神兼前微軟MVP?AmamiyaYuuko?(入職微軟之后就卸任MVP…)開發(fā)維護(hù),不過好像沒有開源,回頭問下看看能不能開源掉。
作者自己的介紹文章:?Timed Job – Pomelo擴(kuò)展包系列
Startup.cs相關(guān)代碼
我這邊使用的話,首先肯定是先安裝對應(yīng)的包:Install-Package Pomelo.AspNetCore.TimedJob -Pre
然后在Startup.cs的ConfigureServices函數(shù)里面添加Service,在Configure函數(shù)里面Use一下。
// This method gets called by the runtime. Use this method to add services to the container. publicvoidConfigureServices(IServiceCollection services) {// Add framework services. services.AddMvc();//Add TimedJob services services.AddTimedJob(); }publicvoidConfigure(IApplicationBuilder app,IHostingEnvironment env, ILoggerFactory loggerFactory) {//使用TimedJob app.UseTimedJob();if (env.IsDevelopment()){app.UseDeveloperExceptionPage();app.UseBrowserLink();}else{app.UseExceptionHandler("/Home/Error");}app.UseStaticFiles();app.UseMvc(routes =>{routes.MapRoute(name: "default",template: "{controller=Home}/{action=Index}/{id?}");});Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); }Job相關(guān)代碼
接著新建一個類,明明為XXXJob.cs,引用命名空間using Pomelo.AspNetCore.TimedJob,XXXJob繼承于Job,添加以下代碼。
public class AutoGetMovieListJob:Job{// Begin 起始時間;Interval執(zhí)行時間間隔,單位是毫秒,建議使用以下格式,此處為3小時;//SkipWhileExecuting是否等待上一個執(zhí)行完成,true為等待;[Invoke(Begin = "2016-11-29 22:10", Interval = 1000 * 3600*3, SkipWhileExecuting =true)]publicvoidRun(){//Job要執(zhí)行的邏輯代碼//LogHelper.Info("Start crawling");//AddToLatestMovieList(100);//AddToHotMovieList();//LogHelper.Info("Finish crawling"); } }?
轉(zhuǎn)載自:http://www.jkeabc.com/432165.html
轉(zhuǎn)載于:https://www.cnblogs.com/ideacore/p/6297759.html
總結(jié)
以上是生活随笔為你收集整理的.Net Core 定时任务TimeJob的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RabbitMQ基础概念详细介绍
- 下一篇: 步步为营-72-asp.net简单练习(