[英]How to call another method using hangfire recurring Job?
I have implemented a method name GetApiData()
.我已经实现了一个方法名称
GetApiData()
。 I want to call this method per minute using hangfire
recurring job.我想使用
hangfire
重复作业每分钟调用一次此方法。 But when I call this method it's showing the error但是当我调用这个方法时,它显示了错误
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()
What will be the proper syntax?什么是正确的语法? It is showing run time error.
它显示运行时错误。
public void APIDataBackgroundJob()
{
RecurringJob.AddOrUpdate(()=>GetApiData(),Cron.Minutely);//This line is showing error
}
you should use like this你应该像这样使用
public void APIDataBackgroundJob()
{
RecurringJob.AddOrUpdate<YourClassContainsThisMethod>(service=>service.GetApiData(),Cron.Minutely);//This line is showing error
}
and be aware you can only use public methods并注意你只能使用公共方法
I think it may be caused by a serialization issue. 我认为这可能是由序列化问题引起的。 Take a look at this: Object getting Null seems like deserialization issue in Hangfire .
看看这个: 获取Null的对象似乎是Hangfire中的反序列化问题 。
Short summary: Try to pass all the instance variables you use inside GetApiData()
as parameters to this method. 简短摘要:尝试将
GetApiData()
使用的所有实例变量作为参数传递给此方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.