Skip to content

Quartz.NET tutorial sample: move to Quartz.NET 4.1.0 - #2221

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78339-quartz4
Sep 17, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78339-quartz4

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Quartz.NET 4.1.0 pass on the dotnet-client-libraries/Quartz.NET sample, which backs the "Quartz.NET in C#: How to Schedule Jobs" article.

Quartz.NET 4 changes the job signature, merges three packages into the main one and removes the interval shorthand, so the sample does not compile as written.

Three files, five hunks, one folder.

  • Quartz.NET.csproj: Quartz 3.19.1 to 4.1.0; Quartz.Extensions.Hosting and Quartz.Serialization.Json dropped (both publish empty forwarding packages on 4.1.0, with hosting, DI and the System.Text.Json serializer inside Quartz); Microsoft.Data.SqlClient 6.1.1 to 7.0.3, the newest stable.
  • BackgroundJob.cs: IJob.Execute moves to ValueTask plus a CancellationToken. The default on the token keeps both existing tests compiling unchanged, so Tests/ is untouched.
  • Program.cs: WithIntervalInSeconds(5) becomes WithInterval(TimeSpan.FromSeconds(5)); UseNewtonsoftJsonSerializer() becomes UseSystemTextJsonSerializer(); ScheduleJob passes ScheduleJobOptions.Replacing.

Why the third Program.cs hunk. With a persistent store the job definition is already in the database on the second start, so the old line throws ObjectAlreadyExistsException before the scheduler runs. Checked against SQL Server 2022 in Docker with the v4.1.0 schema script: one start on an empty database (job persisted, trigger ACQUIRED), one restart without the option (crash), two restarts with it (clean).

dotnet build -c Release: 0 warnings, 0 errors. dotnet test: 2 of 2 passed. SDK 10.0.302, runtime 10.0.10.

Quartz.NET 4 changes the job signature, merges three packages into one and
removes the interval shorthand, so the sample no longer compiles as written.

- Quartz 3.19.1 to 4.1.0. Quartz.Extensions.Hosting and Quartz.Serialization.Json
  are dropped: both publish empty forwarding packages on 4.1.0, and hosting,
  dependency injection and the System.Text.Json serializer are in Quartz itself.
- Microsoft.Data.SqlClient 6.1.1 to 7.0.3, the newest stable.
- IJob.Execute moves to ValueTask plus a CancellationToken, with the default on
  the token so both existing tests keep compiling unchanged.
- WithIntervalInSeconds(5) becomes WithInterval(TimeSpan.FromSeconds(5)).
- UseNewtonsoftJsonSerializer() becomes UseSystemTextJsonSerializer().
- ScheduleJob passes ScheduleJobOptions.Replacing. With a persistent store the
  job definition is already in the database on the second start, and without
  this the sample throws ObjectAlreadyExistsException before the scheduler runs.
  Checked against SQL Server 2022 in Docker: one start on an empty database,
  then two restarts, all clean.

dotnet build -c Release: 0 warnings, 0 errors. dotnet test: 2 of 2 passed.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit e0bf503 into CodeMazeBlog:main Sep 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant