.Net 简单使用 Hangfire
生活随笔
收集整理的這篇文章主要介紹了
.Net 简单使用 Hangfire
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡介
Hangfire 是一個開源框架,可幫助您創建、處理和管理后臺作業(官方文檔)
使用
- 第一步:在Nuget上引用依賴Hangfire
- 第二步:在Configuration注入Hangfire,Configure中使用面板
在Configuration中使用AddHangfire和AddHangfireServer
在Configure中使用面板app.UseHangfireDashboard()
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {if (env.IsDevelopment()){app.UseDeveloperExceptionPage();}else{app.UseExceptionHandler("/Home/Error");// 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.UseHttpsRedirection();app.UseStaticFiles();app.UseRouting();//app.UseHangfireServer(new BackgroundJobServerOptions());//棄用,改成在ConfigureServices中注入services.AddHangfireServerapp.UseHangfireDashboard();//使用面板app.UseAuthorization();app.UseEndpoints(endpoints =>{endpoints.MapControllerRoute(name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");}); }- 第三步:使用
- 第四步:打開面板
hangfire面板是在網站地址后面加hangfire:https://localhost:44398/hangfire/
主頁
服務器
BackgroundJob.Enqueue 立即執行
BackgroundJob.Schedule 延遲任務執行
RecurringJob.AddOrUpdate 周期任務
總結
以上是生活随笔為你收集整理的.Net 简单使用 Hangfire的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C++Primer 第8章IO流
- 下一篇: asp.net ajax控件工具集 Au