I have created a QueuedHostedService extending BackgroundService following official docs here. This runs just fine on development mode and I am able to step into/debug the task passed to the background service when the controller passing the task executes.
However, this doesn’t seem to happen on Staging mode. I could replicate this not only on my staging environment but also on my local using the following launchSettings.json
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55612/",
"sslPort": 44366
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging",
"CONSUL_HTTP_SSL_VERIFY": "0"
}
},
"MyApp": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging",
"CONSUL_HTTP_SSL_VERIFY": "0"
},
"applicationUrl": "http://localhost:55612/;https://localhost:44366/"
}
}
}
My app runs on kestrel server I believe (new to .net – we run the dll with dotnet command), not IIS for which the solution exists here but I couldn’t find any for kestrel.
This has been my analysis. Please let me know what’s wrong or how I can setup kestrel to let BackgroundService run all the time with the lifecycle of the app.