![]() ![]() Next we need to register the Quartz services and the Quartz IHostedService in our app. This adds the hosted service package, which brings in the main Quartz.NET package with in. csproj for the project, it should look something like this: net5.0 dotnet-QuartzWorkerService-9D4BFFBE-BE06-4490-AE8B-8AF1466778FD You can install the Quartz.NET hosting package using dotnet add package. For this test I created a worker service project. NET Standard 2.0 NuGet package, so it should be easy to install in your application. In this post I'll show the basics of creating a Quartz.NET job and scheduling it to run on a timer in a hosted service. You need to configure the scheduler initially, but you don't need to worry about starting or stopping it, the IHostedService manages that for you. It will run in the background of your application, checking for triggers that are firing, and running the associated jobs as necessary. The Quartz.NET hosted service takes care of the scheduler part of Quartz. Quartz.NET also allows you to run multiple instances of your application in a clustered fashion, so that only a single instance can run a given task at any one time. 2:30am), or only on specific days, or any combination of these by using a Cron trigger. You can ensure tasks only run at specific times of the day (e.g. While it's possible to create a "timed" background service, (that runs a tasks every 10 minutes, for example), Quartz.NET provides a far more robust solution. It primarily adds health-check integration, though health-checks can also be used with worker-services too! There is also a Quartz.AspNetCore package that builds on the. can be used either with ASP.NET Core applications, or with "generic host" based worker-services. Quartz.NET version 3.2.0 introduced direct support for this pattern with the package. Hosted services are started when your ASP.NET Core app starts, and run in the background for the lifetime of the application. This is responsible for coordinating the jobs and triggers, executing the jobs as required by the triggers.ĪSP.NET Core has good support for running "background tasks" via way of hosted services. A trigger controls when a job runs, typically firing on some sort of schedule. This is the background tasks that you want to run. NET Standard 2.0, so you can easily use it in your applications. Using Quartz.NET with ASP.NET Core is pretty similar - Quartz.NET supports. It's an old staple of many ASP.NET developers, used as a way of running background tasks on a timer, in a reliable, clustered, way. ![]() Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems. I show how to add the Quartz.NET HostedService to your app, how to create a simple IJob, and how to register it with a trigger. For now you can even get a 40% discount by entering the code bllock2 into the discount code box at checkout at. I also discuss Quartz.NET in the second edition of my book, ASP.NET Core in Action. This post shows how to use that package instead of the "manual" approach in my old post. There's now an official package, from Quartz.NET to do that for you, so adding Quartz.NET to your ASP.NET Core or generic-host-based worker service is much easier. ![]() ![]() This is an update to a post from 18 months ago in which I described how to use Quartz.NET to run background tasks by creating an an ASP.NET Core hosted service. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |