Scheduling code execution at specific intervals is a common requirement in enterprise systems, such as for recurring tasks, maintenance jobs, or periodic data processing. Several approaches are available for implementing scheduling in .NET and NServiceBus-based solutions:
- PeriodicTimer: A lightweight .NET API for running code at regular intervals. See the PeriodicTimer sample.
- System.Threading.Timer: A built-in .NET timer for scheduling recurring or delayed tasks.
- NServiceBus Sagas: Use sagas to coordinate long-running, scheduled, or recurring workflows within NServiceBus.
- Quartz.NET: A powerful, open-source job scheduling library for .NET. See the Quartz.NET sample.
- Operating System Task Schedulers: Use tools like Windows Task Scheduler or Linux cron jobs to run scripts or applications at scheduled times.
- Azure Functions Timer Trigger: Schedule serverless functions to run on a timer in Azure.
- Hangfire: A background job scheduler for .NET applications. See the Hangfire sample.
Choose the approach that best fits your application's requirements and hosting environment.