在一個Net Core需求中,須要在天天的凌晨三點去抓取兩個電商倉庫的剩餘的每一個料號的數量來寫會本身的表中,html
用到了HangFire的定時任務app
這篇文章講的很詳細記錄下 文章2 這篇更簡單async
Quartz.NET總結(三)Quartz 配置
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseHangfireServer(); app.UseHangfireDashboard("/hangfire", new DashboardOptions() { Authorization = new[] { new Code.HangfireMyAuthorizeFilter() } }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); //BackgroundJob.Enqueue<Inv.InventoryTransfer>(x => x.SyncTransfer("Commercial")); } else { //Bob add 設置天天凌晨三點獲取一次即時庫存 string Cron_GetIMInventory = Configuration.GetSection("AppSettings").GetValue<string>("CronGetIMInventory");//獲取到天天的凌晨三點鐘 RecurringJob.AddOrUpdate<DS.PutOMSOrder>("PutOMSOrder", x => x.GetIMInventory(), Cron_GetIMInventory, System.TimeZoneInfo.Local); app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvc(); app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); }