I am working on an asp.net mvc-5 web application. and i install the hangfire tool inside my web application using nuget tool.
https://www.nuget.org/packages/Hangfire/
Then i create the following startup.cs
class, to call a method each minute as follow:-
public class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration
.UseSqlServerStorage("scanservice");
ScanningService ss = new ScanningService();
RecurringJob.AddOrUpdate(() => ss.HypervisorScan("allscan"), Cron.Minutely);
}
}
and here is the definition of the method that will be called :-
public async Task<ScanResult> HypervisorScan(string FQDN)
{
but currently i deploy my application on IIS 7.5 , and the method is not being called at all . so can anyone adivce on this please ?
Thanks
You're missing the OwinStartupAttribute from your class. Add it. That tells OWIN where the code is to run at startup.
Also, you can't run async methods directly in Hangfire as the error clearly states. So wrap the method with a Wait call and pass that to Hangfire.
Lastly, you should stick with the convention that Async methods should end in the suffix Async. Rename ScanningService.HypervisorScan
to ScanningService.HypervisorScanAsync
[assembly: OwinStartup(typeof(MyWebApplication.Startup))]
namespace MyWebApplication
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration
.UseSqlServerStorage("scanservice");
RecurringJob.AddOrUpdate(() => HypervisorScan(), Cron.Minutely);
}
public void HypervisorScan()
{
ScanningService ss = new ScanningService();
ss.HypervisorScanAsync("allscan").Wait();
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.