【发布时间】:2019-04-23 12:24:59
【问题描述】:
我已经实现了一个方法名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
}
【问题讨论】:
-
试试
var myInstance= new MyClass(); RecurringJob.AddOrUpdate(myInstance.GetApiData,Cron.Minutely); -
你能分享堆栈跟踪或
GetApiData方法做什么? -
它一次需要 5 个数据从另一个 api 插入到数据库 @Aarif 的不同表中
-
没有代码,错误是没有意义的。投票结束。
-
尝试提供方法的引用而不是调用它
()=>GetApiData
标签: c# asp.net asp.net-core-2.0 background-process hangfire