如何使用 Hangfire 运行 基于日期时间的重复作业?
How to running a DateTime-based Recurring Job Using Hangfire?
我在 ASP.NET 核心应用程序中使用 Hangfire。我想 运行 一份这样的工作:
() => Console.WriteLine($"Triggered At {DateTime.Now.ToString()} !!")
每分钟。我希望得到这个结果:
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:06:40 PM
Triggered At 5/16/2020 3:07:40 PM
Triggered At 5/16/2020 3:08:40 PM
但我得到的结果如下:
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:05:40 PM
我用过这个代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
...
...
app.UseHangfireDashboard();
RecurringJob.AddOrUpdate("TestJob",
() => Console.WriteLine($"Triggered At {DateTime.Now.ToString()} !!"), "* * * * *");
app.UseMvc();
}
我哪里错了?
谢谢
我认为你应该将它包装在一个方法中。
public static void Method() {
Console.WriteLine($"Triggered At {DateTime.Now.ToString()} !!");
}
RecurringJob.AddOrUpdate("TestJob",
() => Method(), "* * * * *");
我在 ASP.NET 核心应用程序中使用 Hangfire。我想 运行 一份这样的工作:
() => Console.WriteLine($"Triggered At {DateTime.Now.ToString()} !!")
每分钟。我希望得到这个结果:
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:06:40 PM
Triggered At 5/16/2020 3:07:40 PM
Triggered At 5/16/2020 3:08:40 PM
但我得到的结果如下:
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:05:40 PM
Triggered At 5/16/2020 3:05:40 PM
我用过这个代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
...
...
app.UseHangfireDashboard();
RecurringJob.AddOrUpdate("TestJob",
() => Console.WriteLine($"Triggered At {DateTime.Now.ToString()} !!"), "* * * * *");
app.UseMvc();
}
我哪里错了?
谢谢
我认为你应该将它包装在一个方法中。
public static void Method() {
Console.WriteLine($"Triggered At {DateTime.Now.ToString()} !!");
}
RecurringJob.AddOrUpdate("TestJob",
() => Method(), "* * * * *");