Archive for the .NET Core category

Vaughan

Using the new Index and range operators

.NET Core

A great C# feature that was recently released is the new Index and Range operators. Two new system objects were created to make accessing elements or range of elements in arrays shorter and more convenient. Index You can now index an array from the end of the array instead of using Array.Length. To be honest, […]

Read more
Vaughan

A case for pattern matching

.NET Core

Over the years developers using more functional languages like F# have boasted about how much easier their code is to read and how imperative C# can be. NO LONGER! Well maybe not much longer. We are starting to move in the right direction with pattern matching as a good replacement for switch statements. switch statements […]

Read more
Vaughan

Why is async void return bad?

.NET Core

When writing async code, your method is allowed to return either void, Task, Task, or ValueTask). Since early on with async code, the advice has been to not use void return methods. But in real life there are times when you don’t really have a choice. Since we can’t always get away from using them, […]

Read more
Vaughan

Running a .NET Core HostedService as a Windows service

.NET Core

If you need to run your long running .NET Core worker application on a windows server, you can easily install it as a windows service with minimal changes. Just add the following package. Microsoft.Extensions.Hosting.WindowsServices Then all you have to do is add UseWindowsService() to your host builder and its ready to use. public static IHostBuilder […]

Read more
Vaughan

When to consider using ValueTask over Task with async code

.NET Core, BenchmarkDotNet, Benchmarking, Measuring, Performance

As of .NET Core 2.0, you can use ValueTask and ValueTask as return types for your async methods. Its important to understand when and if you should use these instead of a Task and what the trade-offs are if you decide to use it. I would say that if you aren’t measuring the performance of […]

Read more
Vaughan

Counting sheep with BenchmarkDotNet

.NET Core, BenchmarkDotNet, Benchmarking, Measuring, Performance

When trying to improve the performance of your code, the first thing you need to do is measure. If you don’t measure then you won’t know if your changes are actually improving performance. In most cases, there is a trade-off between readability and performance. Often better performing code is more complex and harder to maintain. […]

Read more
Vaughan

Using a custom action constraint to version an endpoint in ASP.NET Core

.NET Core

There are times where you want to add a new action with the same route but you don’t want to break backwards compatibility. One option that could help with this is to use a custom action constraint. I’ve created a controller with two endpoints that have the same route. The Get action could be the […]

Read more
Vaughan

Why concurrency with async beats parallelism for scalability

.NET Core, Measuring, MultiThreading, Performance

Two terms that are often used interchangeably are concurrency and parallelism. It doesn’t help that in English, doing something concurrently means that you are doing more than one thing at a time. In software its a little more complicated. A good explanation on the difference that I have read before is as follows: Concurrency You […]

Read more
Vaughan

Using route constraints in ASP.NET Core

.NET Core

A small but useful feature available in ASP.NET Core is to define route constraints to disambiguate similar routes. Its important to note that the documentation makes it clear that you shouldn’t be using this for input validation. The main use case is if you want different actions using the same route but business logic requires […]

Read more
Vaughan

MEASURING .NET CORE: 5. Creating and analyzing a dump file when an ASP.NET Core application crashes

.NET Core, Dotnet Tools, Measuring

This is the fifth in a series of posts covering measuring a .Net Core application. If you want to try follow the code then you can have a look at this repo: Blog-Diagnostics. This is the plan for the series. I will update this with links as it evolves. Setting up local diagnostics tools Using […]

Read more

BMC logoBuy me a coffee