So the problem is that when your app shuts down, it also kills the background process? I think this is actually correct behavior.

Maybe what you are looking for is IIS configuration to always keep the app domain loaded. The default IIS behavior is to automatically stop your APP if it isn't in use.
https://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html#:~:text=Right-click on the same,waiting for the initial request.