我有一个控制台应用程序用于测试HangFire。这是代码:
using System;
using Hangfire;
namespace MyScheduler.ConsoleApp
{
internal static class Program
{
internal static void Main(string[] args)
{
MyMethod();
Console.WriteLine("[Finished]");
Console.ReadKey();
}
private static void MyMethod()
{
RecurringJob.AddOrUpdate(() => Console.Write("Easy!"), Cron.Minutely);
}
}
}
但它在运行时会抛出异常:
附加信息:JobStorage.Current 属性值尚未初始化,您必须在使用 Hangfire 客户端或服务器 API 之前设置它。
因此我需要一个作业存储来运行它。但所有的示例都是使用 SQL 存储等方式。有没有一种使用某种内存存储来运行此示例的方法?
JobStorage.Current = new SqlServerStorage("ConnectionStringName", options);
// to
JobStorage.Current = new MemoryDbStorage(string.Empty, options);