怪奇物语

怪奇物语

首页 新随笔 联系 管理

# hangfire使用

using System;
using Hangfire;
using Hangfire.SqlServer;
using Hangfire.Storage.SQLite;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            GlobalConfiguration.Configuration
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
                .UseColouredConsoleLogProvider()
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                .UseSQLiteStorage("Data Source=hangfire.db");


            // 队列,执行一次
            BackgroundJob.Enqueue(() => Console.WriteLine("Hello, world!"));

            // 
            BackgroundJob.Schedule(
                () => Console.WriteLine("Hello, world 10s"),
                TimeSpan.FromSeconds(10));

            RecurringJob.AddOrUpdate("easyjob", () => Console.Write("Easy!"), Cron.Minutely);


            using (var server = new BackgroundJobServer())
            {
                Console.ReadLine();
            }
        }
    }
}
posted on 2024-01-09 19:33  超级无敌美少男战士  阅读(58)  评论(0)    收藏  举报