How to use (and test) TimeProvider timers in .NET

Testing timers in C# is difficult, but .NET 8 (C# 12) adds an abstract TimeProvider class that makes it easier. Let’s take a closer look.

January 11, 2024

How to use TimeProvider and FakeTimeProvider (time abstraction in .NET)

Testing time in C# is difficult, but .NET 8 (C# 12) adds an abstract TimeProvider class that makes it easier. Let’s take a closer look.

January 7, 2024

If/else vs switch/case pattern matching

A look at if/else, switch/case, pattern matching, other options … and which is best. (spoiler: none ;) )

November 3, 2023

What are list patterns in C#?

C# has been getting a lot of pattern matching love in recent years, like with list patterns in C# 11. The problem is knowing where and how to use it.

August 31, 2023

What are generic attributes in C# 11?

Generic attributes increase the flexibility of a very early .NET feature. Let’s try using them and see how it keeps our code DRY.

August 23, 2023

Simple ways to notify a user without a MessageBox in WinForms

When sending notifications in a WinForms app, a MessageBox is the only way to go… or is it? Let’s get creative and see what else we might do.

August 16, 2023

How to call an async method from a synchronous one, without deadlocking

Writing async code whenever possible is great, but how do we do it when we’re stuck with legacy (and very synchronous) code?

August 11, 2023

What's the difference between singleton, scoped, and transient?

It’s trivial to register a dependency in a .NET API, but it’s important to clarify a few terms that drastically change a dependency’s lifetime.

July 28, 2023

How can I generate a new GUID?

GUIDs are heavily used in the world of development, so let’s look at a few quick and easy ways to generate them whenever we need them.

July 27, 2023

How to log messages to multiple targets with NLog

When it comes to finding a bug in an app, few things beat a good trail of logs. And for writing those logs, few tools beat NLog in simplicity or flexibility. I rarely appreciate just how flexible it is though, so it’s worth spending a little time taking a closer look.

July 2, 2023