带有.net核心控制台应用程序的Hangfire

时间:2020-06-15 18:08:59

标签: asp.net-core .net-core console console-application hangfire

是否可以通过.Net Core Console Application运行Hangfire?我尝试了下面的代码,如文档“在控制台应用程序中处理作业”一节中提到的那样,但得到“无法加载文件或程序集“ ConsoleAplication1””。有人可以帮我吗?还是一个错误?

services.AddHangfire(config =>
        {
            var hangFireOption = new HangFireOptions();

            config.UseMongoStorage(
                new MongoClient("mongo_connection_string"),
                "database_name",
                new MongoStorageOptions() { MigrationOptions = new MongoMigrationOptions() { Strategy = MongoMigrationStrategy.Migrate, BackupStrategy = MongoBackupStrategy.Collections } });
        });

        services.AddHangfireServer();

完成此配置后,我将在如下所示的hostedService中使用Hangfire循环作业:

RecurringJob.AddOrUpdate("hangfire test console ", () => TestMethod(), Cron.Minutely);

测试方法:

public void TestMethod1()
{
    Debug.WriteLine("hangfire test console 1");
}

谢谢。

0 个答案:

没有答案