Scheduled Jobs in .NET Core 2 Web app hosted in AW

2019-04-16 04:39发布

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

2条回答
放我归山
2楼-- · 2019-04-16 05:19

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

查看更多
倾城 Initia
3楼-- · 2019-04-16 05:21

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.

查看更多
登录 后发表回答