We have implemented a zero-configuration background worker system. You can use background workers for any tasks that need to happen periodically outside of the user context.
To create a new background worker, create a new class derived from
TimedBackgroundWorker. The system will discover it automatically and will register it as a hosted service. That happens in
Program.CreateHostBulder. In your new class, you can inject an ILogger if you need to, but in order to get access to your services, you will need to use the
ServiceProvider property. Then you can call
ServiceProvider.GetService<IEmailService>() for example, to get access to the email service.
RunEveryInSecondsAn abstract property that you have to implement. It defines how often the
Workmethod gets called.
RunOnStartDetermines whether to run the
Workmethod when the service starts.
WorkAn abstract method that you implement in your subclass.
Please note that hosted services run in the same process as the service runtime. So if service is restarted, the background worker may be interrupted. In a future release, we will have HangFire integration to deal with this issue. From more information on hosted services, see Microsoft's documentation.
Table of Contents
- Initial Setup
- Project Structure
- Entity Framework
- User Interface
- Email Service
- Background Workers
- Creating a new Page
- Publishing to Azure