hangfire控制台應用程序中添加控制面板


1.使用nuget 管理包安裝 Microsoft.AspNet.WebApi.OwinSelfHost 

2.根目錄添加新建類 名為:Startup.cs

public class Startup
    {
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder app)
        {

            app.UseHangfireDashboard();
        }
    }

3.打開Program.cs

 static void Main(string[] args)
        {
            GlobalConfiguration.Configuration
               .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
               .UseSimpleAssemblyNameTypeSerializer()
               .UseRecommendedSerializerSettings()
               .UseSqlServerStorage("Server=.;User ID=sa;Password=sasa;database=Hangfire;", new SqlServerStorageOptions
               {
                   CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                   SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                   QueuePollInterval = TimeSpan.Zero,
                   UseRecommendedIsolationLevel = true,
                   UsePageLocksOnDequeue = true,
                   DisableGlobalLocks = true
               });
            using (var server = new BackgroundJobServer())
            {
                BackgroundJob.Enqueue(() => Console.Write("11"));
                string baseAddress = "http://localhost:9001/";
                using (WebApp.Start<Startup>(url: baseAddress))
                {
                    Console.WriteLine("Hangfire Server started. Press any key to exit...");
                    Console.ReadKey();
                }
            }
        }

4.在瀏覽器中打開:http://localhost:9001/hangfire 即可訪問


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM