Professional Development – 2024 – Week 29

Image Credit: https://www.flickr.com/photos/54585499@N04/

.NET

How Thread Safety is Changing in .NET 9 (via Nick Chapsas)

.NET 8 and earlier versions provide a lock block so that you can make operations thread-safe. (Under the hood, this is calling Monitor.Enter and Monitor.Exit.) In .NET 9 there is now a Lock type that behind the scenes is still part of a try-finally block. The new type provides other ways to get information about the lock, and you can also set timeouts (i.e., if I can’t lock within N ms, just exit). You still can’t call async methods in the lock block; use SemaphoreSlim‘s WaitAsync() and Release() methods.

Don’t Use UUIDs/GUIDs in Databases. Use this Instead. (via Nick Chapsas)

ULID (universally unique lexicographically sortable identifier). The current version (UUID v4) has 128 bits of randomness, which can cause fragmentation in data structures. ULID can be encoded in 26 characters (as opposed to 36 characters). It’s time-based and sorts easily. The advantage, though, of waiting for .NET 9’s UUID v7 is that you don’t have to change the datatype (Guid) to anything else; however, there is a .ToGuid() method on the ULID library for .NET.