Tag: ASP.NET Core

Run background processes with the IHostedService and how to inject your services with dependency injection

Many services need background processing. The ASP.NET Core 2.X IHostedService interface gives you an easy implementation skeleton to implement background processes. The Hosted Services are registered in the dependency injection at startup and started automatically. You do not have to do the pluming to get them started at startup. On shutdown you can implement a graceful shutdown. When running background processes there a few pitfalls to avoid. In this blog I’ll introduce the IHostedService and how to avoid common memory leaks when implementing the hosted service.Continue reading “ASP.NET Core background processing with IHostedService”

Working with ASP.NET core I have seen this error multiple times and can be hard to debug. The error can have multiple root causes. It can be a real pain to find the cause and it is sometimes fixed by only taking care of the symptoms. By finding the root cause, you can take the appropriate action in your code.

Lately we had a discussion on when to use ConfigureAwait(true) or ConfigureAwait(false) in ASP.NET Core 2. In the end most of the team, including me, had a faulty assumption on how to do this in ASP.NET Core. In this case ASP.NET Core is different from ASP.NET. Good to know if you have to decide on what to use in ASP.NET core.

Learn how to gracefully handle Application Shutdown in ASP.NET Core by looking at the handling of flushing the application insights messages when asp.net core exits

When running an ASP.NET Core web application, there are cases when you need to do some logic when the application stops. An example: you are logging and have to flush the last message to the log (Application Insights). In that case you need can add an event in the Configure method. In this post I show a short example of how doing this.Continue reading “Application Shutdown in ASP.NET Core with IApplicationLifetime”