Category Archives: C#

Information related to C# and related areas

Windows Special Folders

March 18, 2024

Windows uses an enumeration of special folder names to make it easier to find commonly used folders. Without this mechanism, we’d have to jump through a lot more hoops to determine this information since it is user dependent. I was trying to use a special folder as the root of a path for some common files shared by… Read More »

Use CancellationToken to Make Responsive Thread.Sleep() Wait

January 30, 2024

Using a time delay based on a Thread.Sleep() is truly easy. However, if you need a pause inside code that is using a CancellationToken, be aware that if the CancellationTokenSource calls the Cancel() method, Thread.Sleep() will ignore the request. CancellationToken Aware Sleep() In the example below, we get the WaitHandle from the token and pass in delay time… Read More »

Stop Debug Messages from Disrupting Unit Tests

June 8, 2023

When writing code, I frequently add Debug checks to alert me that an incorrect assumption has been made. During development (debug build code), I want to know I haven’t handled a case. During production (release build code), I don’t want to interrupt the user experience. This means that for an unhandled case, the method should be written to… Read More »

Quickly Create JSON Serialization Classes

February 8, 2023

If you have a non-trivial JSON object, it can be time consuming to create classes the can be used for serialization/deserialization. This web site can help you out no matter what type of language you want to work with. Procedure The resulting classes are regenerated automatically if you modify any settings or change the JSON file. Copy the… Read More »

C# Debug Exception Viewer

January 24, 2023

It’s simple enough to add a try/catch block around code to catch any exception. But when you are in the initial stages of generating code, you want quick feedback and it doesn’t exactly need to be pretty. In the catch block, pass the exception to this method to create a string with easy to read information. The Code… Read More »