• Stars
    star
    262
  • Rank 155,438 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created about 4 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Schedule Cron Jobs using HostedService in ASP.NET Core

Service Worker Cron Jobs Demo

Buy Me a Coffee at ko-fi.com

You may want to ask, "What's the difference between a hosted service and a background thread?" The difference is that the hosted service will be started and stopped with the application. While, when starting a background thread, the thread cannot gracefully handle clean-up actions and will be killed when the application is stopped. The HostedServiceExecutor will handle the starting and stopping of a hosted service, which allows for graceful cleanup when the application is stopped.

Starts from version 2.1, .NET Core provides a native abstract base class BackgroundService, which includes common operations for background jobs such as CancellationToken and housekeeping works.

Medium Article: Schedule Cron Jobs using HostedService in ASP.NET Core

In this blog post, we will go over the use case of scheduling cron jobs using a customized HostedService in an ASP.NET Core Web API project. The following screen recording shows the runtime logging for the final application, which has three background tasks running at every 5 minutes, every 1 minute, and every day at 12:50 PM.

Cron Jobs

License

Feel free to use the code in this repository as it is under MIT license.

Buy Me a Coffee at ko-fi.com

More Repositories

1

JwtAuthDemo

ASP.NET Core + Angular JWT auth demo; integration tests; login, logout, refresh token, impersonation, authentication, authorization; run on Docker Compose.
C#
342
star
2

Minimal-URL-Shortener

An example web app based on the new feature in .NET 6 | minimal web API in ASP.NET 6
C#
125
star
3

HeadFirstDesignPattern

Head First Design Pattern: Completely Rewrite in C#
C#
50
star
4

ApiAuthDemo

A simple demo with JWT Auth APIs and Basic Auth APIs, with Swagger support. Swagger Security; Swagger Auth
C#
47
star
5

SftpService

Working with SFTP in .NET Core
C#
45
star
6

NginxLoadBalancer

Host an ASP.NET Core App with Nginx and Docker: SSL and Load Balancing
C#
42
star
7

FileTransferUsingHttpClient

Upload/Download Files Using HttpClient in C#
C#
34
star
8

HerokuContainer

Dockerized ASP.NET Core Web API app in Heroku
C#
31
star
9

AngularFileUpload

Upload files from Angular client to a .NET API endpoint
C#
26
star
10

WindowsServiceDemo

Windows Service in ASP.NET Core
C#
21
star
11

SemaphoreSlimThrottle

Rate Limiting API Endpoints in ASP.NET Core
C#
20
star
12

ApiControllerIntegrationTests

Integration Tests for API Controllers using MSTest
C#
16
star
13

HandwritingRecognition

Handwriting Recognition using ML.NET
C#
15
star
14

PatternMatchingDemos

Using Pattern Matching to Avoid Massive "if" Statements
C#
13
star
15

Client-IP-SafeList

Client IP safelist for ASP.NET Core | .NET 5 | CIDR | Network | allowed list | IP restriction
C#
12
star
16

CustomConfigurationProviderDemo

Create a Custom Configuration Provider in ASP.NET Core
C#
12
star
17

OptionsPattern

Options Pattern in .NET Core
C#
9
star
18

RunExeFromWebApi

Run an External Executable in ASP.NET Core
C#
7
star
19

UnitTestingWithILogger

Unit Testing with .NET Core ILogger<T>
C#
7
star
20

JsonLabs

Working with JSON in .NET Core 3
C#
7
star
21

KestrelHttps

Enforce HTTPS for an ASP.NET Web API hosted in Kestrel
C#
6
star
22

SerilogFilterDemo

Set up Serilog for .net applications
C#
6
star
23

ChainOfResponsibility

Design Pattern - Chain of Responsibility
C#
4
star
24

Immutable-Collection-InMemory-Cache

Working with Cache using Immutable Collections
C#
4
star
25

SslCertificateChecker

Check SSL Certificate Details Using .NET 6+
C#
3
star
26

BuilderPattern-Moq-UnitTests

Builder Pattern vs Moq in Unit Tests
C#
3
star
27

NETCoreGlobalTools

Create a custom .NET Core CLI tool
C#
2
star
28

HeadFirstOOAD

Coding practice when read HeadFirstOOAD book
C#
2
star
29

StringTemplates

How to Create String Templates in CSharp
C#
2
star
30

ConcurrencyControl

Entity Framework Core Concurrency Control Demo
C#
2
star
31

ConfigurationBuilderDemos

ConfigurationBuilder Demos: APS.NET Core configuration
C#
1
star
32

XmlDocumentationDemo

XML Documentation in CSharp
C#
1
star
33

LifetimeEventsDemo

A demo about the ASP.NET Core Lifetime Events
C#
1
star
34

MemoryCacheLabs

Cache in-memory in ASP.NET Core | tests | immutable
C#
1
star
35

ControllerUnitTests

Unit testing Controllers with ClaimsPrincipal | User | Identity | Claims
C#
1
star