如何使用hangfire定期Job调用另一种方法?

问题描述 投票:0回答:1

我已经实现了一个方法名称GetApiData()。我希望每分钟使用hangfire重复工作来调用此方法。但是,当我调用此方法时,它显示错误

System.ArgumentNullException: Value cannot be null.
Parameter name: method
   at Hangfire.Common.Job..ctor(Type type, MethodInfo method, Object[] args)
   at Hangfire.Common.Job.FromExpression(LambdaExpression methodCall, Type explicitType)
   at Raasforce.Crm.ContactRepositoriesAppService.APIDataBackgroundJob() in E:\RaasforceCorp\RaasforceCorp\aspnet-core\src\Raasforce.Application\Crm\ContactRepositoriesAppService.cs:line 795
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.<>c__DisplayClass33_0.<WrapVoidMethod>b__0(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.VoidResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()

什么是正确的语法?它显示运行时错误。

public void APIDataBackgroundJob()
{
    RecurringJob.AddOrUpdate(()=>GetApiData(),Cron.Minutely);//This line is showing error
}
c# asp.net asp.net-core-2.0 background-process hangfire
1个回答
0
投票

我认为这可能是由序列化问题引起的。看看这个:Object getting Null seems like deserialization issue in Hangfire

简短摘要:尝试将您在GetApiData()中使用的所有实例变量作为参数传递给此方法。

© www.soinside.com 2019 - 2024. All rights reserved.