The first in a series of beginner posts on debugging skills, this will introduce you to one of the most basic and fundamental debugging techniques – Breakpoints.

This won’t take long. Breakpoints are a simple concept but one that can elude new programmers for a while. I recall my early days in college when hearing about debugging with breakpoints seemed “advanced”. I know this is still a problem by my observations made from questions.

A program is a process and a debugger attaches to that process to provide debugging services. Modern integrated development environments (Visual Studio, Eclipse, Android Studio, Visual Studio Code, etc., etc.) can automatically run and attach a debugger to your program. If you have set a breakpoint, the code will pause execution on that line and wait for you to allow it to continue. While paused, there are a myriad of things you can do to interrogate the state of your program. Exactly what you can do depends on your IDE but all modern IDE’s support very similar capabilities.

Let’s look at a quick demo. I am using the built-in Chrome Developer Tools against a my demo site

I have chosen to demo a website because nearly everyone has Chrome and the Internet. Your language and environment will work very similarly to this process.

ConfigureAwait (sometimes) Saves the Day Everytime!

I get in a lot of fights.

Fights about async/await anyway. Despite async/await being over 5 years old (AOTW), there still remains a lot of confusion regarding some basic functionality.

I do not presume to be an in-depth expert. Some of the things I read from Stephen Cleary or Jon Skeet make my eyes go crossed. But for your average, everyday usage, it doesn’t need to be so misunderstood.

I am not going to rehash the excellent articles that explain these things. I am going to share a WPF application that demonstrates some of the commonly misunderstood pitfalls so you can actually observe the things you read about by the experts like Stephen Cleary, Stephen Toub, Jon Skeet.

Introducing “WPFGui”…. This is a simple Windows Presentation Foundation application that will attempt to update the UI on each of the button clicks. Of course I don’t need to update the UI directly with MVVM, but this is a contrived example after all….

Continue reading

Using HttpClient as it was intended (because you’re not)


Async programming has become ubiquitous and the standard tool for making async HTTP requests with C# is HttpClient from the System.Net.Http namespace. Examples are aplenty, but good examples are few and far between. Because HttpClient implements IDisposable we are conditioned to new it up in a using statement, make the call and get out as fast as possible.

This is WRONG.

This blog post will pull together advice from the few good resources online that touch on various aspects of why you are using it wrong, and how to use it correctly.

Continue reading

C# Data Binding example with Adapters and DataGridView


A Basic Example of CRUD with DataGridView in VB.Net being one of my more popular posts, I thought I should provide a C# example. I find people on continue to struggle with setting up DataAdapters to perform inserts, updates and deletes, and the use of WinForms is still often the platform used by beginners and students.

So here is a small sample application demonstrating how easy it is. There is an embeded SQLite database so you can immediately run the project without worrying about database setup. The code itself is easily translated for your data provider of choice – where you see “SQLite” just replace it with “SQL” or “OleDB”, or whatever you are using:

SQLiteCommand => becomes => SqlCommand

This time I’ll allow the code to speak for itself, get it here on GitHub.

Fun With NTFS Alternate Data Streams

Are you familiar with the feature of NTFS called Alternate Data Streams? Our typical usage of files is pretty simple. We double click it and it opens. But  by default we are only accessing the “default” data stream. We can write to multiple data streams, effectively storing multiple files in a single file. These alternate streams are generally hidden, but we can see them and even write to them. I’ll show  you how to do it from the command line and from C#.

Continue reading

Custom Serilog Sink Development

The code shown here is part of a VS 2015 solution hosted on GitHub.

If you are coming to this blog post you probably already know what Serilog is and you need to write to a “sink” that is not already provided in the list of Available Sinks. The list is quite long so definitely look closely before developing your own because there is most likely one already built for  your needs.

But what if there isn’t? Continue reading