Programming Tips 💡
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips 💡
Articles 📕
Resources 👾
Design Patterns 💎
Software Principles

🇳🇱 Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
Running async tasks on app startup in ASP.NET Core 3.0 ⚡️

In this post, I describe how a small change in the ASP.NET Core 3.0 WebHost makes it easier to run asynchronous tasks on app startup using IHostedService.

Unfortunately, in 2.x it wasn't possible to use any of the built-in ASP.NET Core primitives to achieve this :

• IStartupFilter has a synchronous API, so would require doing sync over async. 🤦🏻‍♂️

• IApplicationLifetime has a synchronous API and raises the ApplicationStarted event after the server starts handling requests. 🤷🏻‍♂️

• IHostedService has an asynchronous API, but is executed after the server is started and starts handling requests. 👍🏻

With ASP.NET Core 3.0, a small change in the WebHost code makes a big difference - we no longer need these solutions, and can use IHostedService without the previous concerns❗️


[ Article ] : kutt.it/asphost

〰️〰️〰️〰️〰️〰️
#AspNet #AspMvc #AspCore
@ProgrammingTip