I have an asp.net core application running on windows server. This is using some background tasks for using external service to get the data. We are facing an issue that after our app pool recycled/restarted, the background task is not running. This is running only after we are accessing the application. We found an article regarding this.
Since this article describe asp.net application, below code will substitute the above solution in .net core application
public class Startup
{
public void Configure(IApplicationBuilder app)
{
var applicationLifetime = app.ApplicationServices.GetRequiredService<IApplicationLifetime>();
applicationLifetime.ApplicationStopping.Register(OnShutdown);
}
private void OnShutdown()
{
// Do your cleanup here
}
}
Is there any other work around to solve this issue?