skip to content
Relatively General .NET

Too many timers in .NET?

by Gérald Barré

posted on: March 20, 2023

There are at least 6 different timers classes in .NET! Each timer has its purpose and use-case. I will try to explain the differences between them.First, there are UI-specific timers. These timers are used to execute code on the UI thread. They are:System.Windows.Forms.TimerSystem.Windows.Threading

Working with Git in JetBrains Rider

by Andrew Lock

posted on: March 14, 2023

In this post, I describe how I work day-to-day with Git using JetBrains' Rider, working exclusively with keyboard shortcuts, but with the benefits of a GUI…

ExternalFinalizer: Adding a finalizer to 3rd party objects

by Oren Eini

posted on: March 13, 2023

Let’s say that you have the following scenario, you have an object in your hands that is similar to this one: This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public class Frame : IDisposable { private void* _data; private int _len; public Frame(int size) { _len = size; _data = NativeCalls.AllocateFrame(size) ?? throw new OutOfMemoryException(); } public void Dispose() { NativeCalls.FreeFrame(_data,_len); } } view raw Item.cs hosted with ❤ by GitHub It holds some unmanaged resources, so you have to dispose it. However, this is used in the following manner: This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public Frame CurrentFrame => _frame; public void UpdateFrame(Frame f) { var old = _frame; _frame = f; old.Dispose(); } view raw Usage.cs hosted with ❤ by GitHub What is the problem? This object may be used concurrently. In the past, the frame was never updated, so it was safe to read from it from multiple threads. Now there is a need to update the frame, but that is a problem. Even though only a single thread can update the frame, there may be other threads that hold a reference to it. That is a huge risk, since they’ll access freed memory. At best, we’ll have a crash, more likely it will be a security issue. At this point in time, we cannot modify all the calling sites without incurring a huge cost. The Frame class is coming from a third party and cannot be changed, so what can we do? Not disposing the frame would lead to a memory leak, after all. Here is a nice trick to add a finalizer to a third party class. Here is how the code works: This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters public ConditionalWeakTable<Frame,FrameDisposer> _linkInstances = new(); public class FrameDisposer { public Frame Frame; ~FrameDisposer() { Frame.Dispose(); } } public void UpdateFrame(Frame f) { var old = _frame; _linkInstances.Add(old, new FrameDisposer{ Frame = old } ); _frame = f; } view raw ExternalFinalizer.cs hosted with ❤ by GitHub The ConditionalWeakTable associates the lifetime of the disposer with the frame, so only where there are no more outstanding references to the frame (guaranteed by the GC), the finalizer will be called and the memory will be freed. It’s not the best option, but it is a great one if you want to make minimal modifications to the code and get the right behavior out of it.

Measuring performance of Roslyn Source Generators

by Gérald Barré

posted on: March 13, 2023

A Roslyn source generator is a tool that allows you to programmatically generate C# or VB.NET source code at compile time. Source generators are implemented as Roslyn analyzers, which are NuGet packages that contain one or more source generators. When you include a source generator NuGet package in

Next week: Kobo's Journey Into High Performance and Reliable Document Databases at InfoQ

by Oren Eini

posted on: March 10, 2023

Trevor Hunter from Kobo Rakuten is going to be speaking about Kobo’s usage of RavenDB in a webinar next Wednesday. When I started at Kobo, we needed to look beyond the relational and into document databases. Our initial technology choice didn't work out for us in terms of reliability, performance, or flexibility, so we looked for something new and set on a journey of discovery, exploratory testing, and having fun pushing contender technologies to their limits (and breaking them!). In this talk, you'll hear about our challenges, how we evaluated the options, and our experience since widely adopting RavenDB. You'll learn about how we use it, areas we're still a bit wary of, and features we're eager to make more use of. I'll also dive into the key aspects of development - from how it affects our unit testing to the need for a "modern DBA" role on a development team. About the speaker: Trevor Hunter: "I am a leader and coach with a knack for technology. I’m a Chief Technology Officer, a mountain biker, a husband, and a Dad. My curiosity to understand how things work and my desire to use that understanding to help others are the things I hope my kids inherit from me. I am currently the Chief Technology Officer of Rakuten Kobo. Here I lead the Research & Development organization where our mission is to deliver the best devices and the best services for our readers. We innovate, create partnerships, and deliver software, hardware, and services to millions of users worldwide." You can register to the webinar here.

2022 Year in Review

by Ardalis

posted on: March 10, 2023

This is something I usually try to write in early January but here it is March already and I'm finally feeling up to it. It's been a rough…Keep Reading →

Drawing graphs in GitHub comments with Mermaid diagrams

by Andrew Lock

posted on: March 07, 2023

In this post I show how I hacked graphs into GitHub PR comments using Mermaid diagrams…

Testing Roslyn Incremental Source Generators

by Gérald Barré

posted on: March 06, 2023

Roslyn Source Generators allow generating code based on the current project code and additional files. Each keystroke in the editor may trigger source generators. So, it is important to ensure that the source generators are fast enough to not impact the user experience. One important feature is inc

RavenDB Sharding Progress

by Oren Eini

posted on: March 02, 2023

RavenDB Sharding is now running as a production replication in our backend systems and we are stepping up our testing in a real-world environment. We are now also publishing nightly builds of RavenDB 6.0, including Sharding support. There are some known (minor) issues in the Studio, which we are busy fixing, but it is already possible to create and manage sharded clusters. As usual, we would love your feedback. Here are some of the new features that I’m excited about, you can see that we have an obese bucket here, far larger than all other items: And we can drill down and find why: We have quite a few revisions of a pretty big document, and they are all obviously under a single bucket. You can now also get query timings information across the entire sharded cluster, like so: And as you can see, this will give you a detailed view of exactly where the costs are. You can get the nightly build and start testing it right now. We would love to hear from you, especially as you test the newest features.

Customising the RequestDelegate with filters

by Andrew Lock

posted on: February 28, 2023

Behind the scenes of minimal APIs - Part 8