Lazy<T> and singletons done right
The static Instance property, the hand-rolled double-checked lock and the Lazy<Task
The static Instance property, the hand-rolled double-checked lock and the Lazy<Task
BlockingCollection blocks threads, BufferBlock pulls in a whole dataflow library for a queue, and a hand-rolled Queue plus lock is a race condition waiting to happen. System.Threading.Channels is the async-native producer/consumer queue, with backpressure and completion built in.
A static "current machine state", fields that every method changes, and a lock that guards half of a huge class. Why shared mutable state makes code untestable and unsafe, and how records, pure functions, small classes and the right concurrent types get you out.