是否有适用于Hangfire的内存中作业存储包? [英] Is there an in memory job storage package for Hangfire?
本文介绍了是否有适用于Hangfire的内存中作业存储包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个控制台应用程序来测试HangFire.这是代码:
I have a console application to test HangFire. Here is the code:
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);
}
}
}
但是它会在运行时引发异常:
But it throws an exception on runtime:
其他信息:JobStorage.Current属性值尚未确定 初始化.您必须先设置它,然后才能使用Hangfire客户端或服务器 API.
Additional information: JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.
所以我需要一个作业存储来运行它.但是,SQL存储中的所有示例均如此.是否可以使用某种内存存储来运行此示例?
So I need a job storage to run this. But all examples in SQL storage etc. Is there any way to run this example with some kind of memory storage?
JobStorage.Current = new SqlServerStorage("ConnectionStringName", options);
// to
JobStorage.Current = new MemoryDbStorage(string.Empty, options);
推荐答案
您可以使用 Hangfire.MemoryStorage 为此.
只需添加此nuget包.
然后您可以像使用它一样-
And then you can use it like -
GlobalConfiguration.Configuration.UseMemoryStorage();
这篇关于是否有适用于Hangfire的内存中作业存储包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文