问题
We are starting a new project in .NET Core 2, I will be needing some approach to run a scheduled job that will do some work. This app will be hosted in Linux server or AWS linux instance. I have done this with Azure WebJobs and .NET 4.6. How is this done with .Net Core and Linux
回答1:
I dont know who upvoted this question. I went out and used Hangfire Jobs. Pretty easy to work. not actually a scheduled job. But we can start it with a Run() and be on our way doing other things. No need to wait for it to end. If anyone need a detail. plz comment
回答2:
Depending on your use case maybe implementing the IHostedService interface (available since .NET Core 2.1, with copy-paste also useable with .NET Core 2.0) is sufficient. If you just want to do some periodic clean-up in the background, you could run it using a timer. See: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/hosted-services?view=aspnetcore-2.1
The advantage of implementing IHostedService is that you can react to the shutdown of the service.
来源:https://stackoverflow.com/questions/46321059/scheduled-jobs-in-net-core-2-web-app-hosted-in-aws