是否可以通过.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");
}
谢谢。