Author Archives: Jerome

About Jerome

I am a senior C# developer in Johannesburg, South Africa. I am also a recovering addict, who spent nearly eight years using methamphetamine. I write on my recovery blog about my lessons learned and sometimes give advice to others who have made similar mistakes, often from my viewpoint as an atheist, and I also write some C# programming articles on my programming blog.

Here’s the first version of my code using Microsoft.IO.RecyclableMemoryStream

I mentioned a while back that I was going to do this… The app is heavy with its usage of streams, so replacing all references to MemoryStream with one that reuses pooled buffers seemed like a logical thing to do. … Continue reading

Posted in Programming | Tagged | Leave a comment

Another example of a control hosted in a ToolStrip: ToolStripCustomProgressBar

First off, while taking screenshots to use in this post, I found an issue in my ffmpeg wrapper, which specified “libvo_aacenc” for the aac audio encoder. It turns out that has since changed and because I recently updated the ffmpeg … Continue reading

Posted in Programming | Tagged , | Leave a comment

I see my ImageComboBox and ToolStripImageComboBox was broken.

So I fixed it. Not sure when it broke. Also I don’t think I shared it before… Anyway, here it is now, and it’s fixed in my full source code archive too. The issue was the native struct pinvoke declaration … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

My custom ToolStripSlider Windows Forms control

In the last post I shared the full source code of my jack-of-all-trades application. Since you can get the code there, I can now share classes and the code for controls, even if they refer to image resources in the … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

All the c# source code of the last few articles, and then some…

I guess it will never really be ready to share, so here it is… as is. My old share that you’ll find links to in older posts, was shared on OneDrive. This is on Google drive. You’ll find two zip … Continue reading

Posted in Programming | Tagged , | Leave a comment

Ever wondered how code can estimate the size of an image to be saved?

This is an idea I came up with a few years ago, while high on meth, so how clever it really is, is probably debatable. I’d noticed how applications that can save images always have this feature where they tell … Continue reading

Posted in Programming | Tagged , | Leave a comment

Still not ready to share the full source code

I mentioned yesterday that I intend sharing the full source code of my mostly experimental application. But I’m not quite ready yet. I’ve updated the code base fully now, for VS 2019, and addressed the worst bugs that I knew … Continue reading

Posted in Programming | Tagged | Leave a comment

Extracting shell images for files and directories in c#

I did share my application’s full source code years ago, but that was way out of date and I should update it at some point. Anyway… my app is mostly an image viewer like the old ACDSee application, and it … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Some Task extensions

I’m on a 30 day Facebook ban because I called some Donald Trump supporters white trash. Apparently I, a white South African, am guilty of hate speech and racism against white people. But actual hate speech, often subtle, always insidious, … Continue reading

Posted in Programming | Tagged , | Leave a comment

Here are my Stream extensions, including a c# wrapper for the ReOpenFile Windows API function, and some code that uses my CopyToStreamAsync extension method.

I don’t have many Stream extension methods, in fact there are only two, but I think they are useful. CopyToStreamAsync, an extension to Stream, is an alternative to Stream.CopyToAsync, and is featured in one of my most popular posts. ReOpen, … Continue reading

Posted in Programming | Tagged , , , , , , , , , | Leave a comment

How to pause or resume a process with c#

I wrote this post already, but the plugin I used back then formatted the code badly, so here is the subject again… The code shared today is slightly different to the original post since I have been updating my old … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Resize an image in c#

Still looking through my old code as I update it for Visual Studio 2019, I found this… I have several extension methods for saving and converting images. Some of them use my async extension methods for handling streams and some … Continue reading

Posted in Programming | Tagged | Leave a comment

How to indicate the Windows display is in use (and also enable or disable the screen saver) with c#

Still going through my old code, and I found this… One part of my application is a video player, but if you’ve ever written one and used it to watch a video that’s more than a couple of minutes or … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Using c# to copy, move, rename files, and delete to the recycle bin via SHFileOperation

While we’re on the subject of deleting files as in the last post, I found this old code of mine in the same solution. I don’t use it anymore because I use IFileOperation instead, but this code still works. (The … Continue reading

Posted in General, Programming | Tagged , , | Leave a comment

Some slight overkill for a method that deletes files and directories

Still cleaning up and improving my old code… I found this. It’s a method in my base class for console applications, to handle deleting files. This is something I’ve approached in different ways in different places – even in the … Continue reading

Posted in General, Programming | Tagged , | Leave a comment

Using a Folder Browser Common Dialog in c#

Lately I have been taking my old solution, which contains a large amount of my personal and experimental code, and updating it for Visual Studio 2019, since there are several wizards which help people like me who have missed all … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Saving a collection of images to a high quality GIF animation using c#

I ran into an interesting problem this weekend… I was showing off a feature of my code to my son, and it didn’t work as expected… I have this application with years of my personal code, which I have recently … Continue reading

Posted in Programming | Tagged , | Leave a comment

Locating and running msbuild from the command line in Visual Studio 2019

Yesterday I installed Visual Studio 2019 Community Edition on my home machine. I went straight up from 2015 to 2019, and lo and behold, my build script, for my sample app that contains all my experimental code, no longer works. … Continue reading

Posted in Programming | Tagged | Leave a comment

Easily draw semi-transparent text on an image in c#

I had a requirement to return an image with text on it, and it turns out this is really easy to do in c#. My code is running in a WCF service so my input and outputs are base64-encoded strings, … Continue reading

Posted in Programming | Tagged , | Leave a comment

Subclassing Exception to log some contextual information

Today I arrived at work to find some truly wonderful emails in my inbox, containing the informative error: String or binary data would be truncated. So somewhere in a public method, one of the members of a structure in scope … Continue reading

Posted in Programming | Tagged , | Leave a comment

Sorry I took that last post down…

This past Monday I published a post with a helper class for relaying HTTP POST requests from one WCF service to another, detailing how to create a relay service in c#. Then I took it down right away. Sorry about … Continue reading

Posted in General, Work | Leave a comment

The most annoying kind of error message?

What is the most annoying kind of error message, from a technical perspective? Or from the perspective of an error that was reported from an end user where you are a developer or in technical support? I’ve changed my mind … Continue reading

Posted in General, Programming, Work | Tagged | Leave a comment

My poor man’s factory pattern in c# – one way of instantiating all derived classes of an abstract base class

Apologies for deleting yesterday’s post. It used my actual code and the syntax highlighting was broken in my Open Live Writer. This one uses simplified code that I wrote in an example solution, and thus does not involve me sharing … Continue reading

Posted in Programming | Tagged , , | Leave a comment

A straightforward implementation of ISynchronizeInvoke in c#

I ran into an unusual problem the other day… I’m developing a control that under the hood uses one of three implemented fingerprint scanner API’s in c#. My code is not complicated… just use the relevant DLLs and have their … Continue reading

Posted in Programming | Tagged , | Leave a comment

Updating a table using a join in SQL Server (UPDATE FROM)

Yes, this is most probably trivial to everybody except me. For whatever reason, I simply don’t remember this syntax. Every time I have to do this, I Google it and usually end up on this solution. You can go there … Continue reading

Posted in Database, SQL | Tagged , , | Leave a comment

Split a List<T> into smaller lists of size N.

Well, my stupid header (created years ago when I was still a tweaker) promises an occasional descent into madness, so here you go… use this code at your own risk. Every so often I find that I have a generic … Continue reading

Posted in General, Work | Tagged , | Leave a comment

Emails I hate receiving

I often wonder if I am the only one who hates receiving emails like this… Names have been omitted. Subject: Problem with [product brand name]. Hi asshole I trust this email finds you well. Please assist with the below. OR… … Continue reading

Posted in General, Work | Leave a comment

How to initialize an enum from a string or int value in c#

I didn’t know you could do this, but I tried and it seems fine so it’s worth sharing. I’m working in a large code base, where my input might come from a web form, or an imported file, or even … Continue reading

Posted in Programming | Tagged , | Leave a comment

New methods not showing up in WCF Test Client? Are you using IIS Express and did you move your code to a new directory without deleting the old one?

I gave the answer to my problem of today in the title… I work on multiple projects. But we also recently changed our source control provider from SVN to Git. If I haven’t touched a code-base for months, I don’t … Continue reading

Posted in Programming | Tagged | Leave a comment

Sample code to send email via gmail in c# (updated)

I wrote a post recently with some code to send email via gmail in c#. The other day, I needed to update it to allow for multiple attachments. Rather than update the original post, I’ve written this new one… (The … Continue reading

Posted in Programming | Tagged , | Leave a comment

Sample code to send email via gmail in c#

For some time, I’ve had a block of code that I copied and pasted all over the place, to send emails via gmail. It didn’t add an attachment, but I needed to do so today. So rather than copy and … Continue reading

Posted in Programming | Tagged , | Leave a comment

Beware of calling Contains in the Where predicate on IQueryable<T> in LINQ to SQL if your collection has more than 2100 items

Recently I ran into a problem I’d never seen before – the 2100 parameter limit in the SQL that’s generated when you call Contains in the IQueryable<T>.Where predicate in LINQ to SQL. To make matters worse, this happened when filtering … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to load a cursor from embedded resources in C#

Last night, being the last night my son was staying with his cousins, I was bored and spent some time looking at some old code. I don’t know if anyone else still uses Windows Forms applications, but in case you … Continue reading

Posted in Programming | Tagged , , | 1 Comment

A pet hate and anti-pattern: A method returning a bool that can never return false, but can throw an Exception.

Recently I came across some code that, while syntactically correct, does something that always gets to me. Let’s illustrate it with an example: using System; namespace Example { public class AntiPatterns { public bool NeverReturnsFalse() { try { // Do … Continue reading

Posted in Programming | Tagged | Leave a comment

Beware of WCF POST service methods that receive JSON that contain DateTime values

I ran into a weird problem today… I have a third party that returns some data to our endpoint in JSON format. I created my endpoint, posted JSON to it, and all seemed well. But when the third party posted … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

T-SQL to get the counts of records within age ranges

This post is written just in case future me has to do this again… I was emailed a spread sheet containing thousands of birth dates by my boss, and asked to return a segregation based on the number of them … Continue reading

Posted in Database | Tagged | Leave a comment

How to convert a string to ASCII in c#

This is one of those cases where smart-ass developers will tell you that you should not be converting strings to ASCII, because reasons… However, if you’re sending a file to a host-to-host banking system, or sending text to an external … Continue reading

Posted in General, Programming | Tagged | Leave a comment

How to save a simple tabular Excel file from C# using EPPlus

An application I wrote was exporting a couple of different sets of objects as CSV files, but the people using it wanted Excel files. Although Microsoft designed C# and everybody involved assumed that such formats are native to dot Net, … Continue reading

Posted in Export XLSX file | Tagged | 1 Comment

A SQL helper class that allows executing a query or running a stored procedure, with or without dynamic parameters

A while back I wrote about my extension method to copy a non-generic collection to an array. A commenter pointed out that it isn’t really necessary. Oh well… here is some code that uses it… (If you use this code, … Continue reading

Posted in Database, SQL | Tagged , | 1 Comment

Who else modified QBASIC’s NIBBLES to run on Windows 95?

I just read a blog post by Raymond Chen. It’s a  historical post about getting an old MS-DOS game to run on Windows 95… But what really got my attention was one of the comments, where the commenter mentioned a … Continue reading

Posted in General | Tagged | Leave a comment

I hate SQL. One way of doing a subquery in a JOIN statement

I really do. I’m writing this mostly for myself because I never remember this shit. I wrote this query  now but I know that I won’t remember how to do this in future, so here is the public note to … Continue reading

Posted in Database, SQL | Tagged | 1 Comment

When cleanup fails and tells me that I need to run cleanup

Huh? Normally I wouldn’t write a post like this because I don’t have a solution. But this one is just too funny in its own stupid way. Yesterday I needed to commit a simple change to a project, and we … Continue reading

Posted in Programming, Work | Tagged | Leave a comment

Convert a non-generic collection to an array – my most useful extension method ever…

Funny how things work out… I wrote one of my most simple extension methods years ago, one that converts a non-generic collection to an array (because arrays implement IEnumerable<T> on which I can call Linq extension methods). Lately I find … Continue reading

Posted in Programming | Tagged , , | 2 Comments

How to get the row index in the client side code of a DataItemTemplate in an ASPxGridView column

This was pissing me off for far too long today. I also have a DataItemTemplate with an ASPxHyperlink control in one of my columns of an ASPxGridView. When the user clicks the hyperlink, I need to call a JavaScript function … Continue reading

Posted in Programming | Tagged , , , | 2 Comments

How to insert multiple literals explicitly into a table, only if they don’t already exist

It might seem silly, but recently I needed to insert some values into a new table I added to a system, but only if those values didn’t already exist, and I did not know how. (Yes, it’s a new table … Continue reading

Posted in SQL | Tagged , | Leave a comment

How to add to the Windows recent documents in C#

I realize that I haven’t written anything here for ages… so I looked through my old code for something simple but useful, and found this. If ever you need to add a file to the Windows recent document list, this … Continue reading

Posted in Programming | Tagged , | Leave a comment

Spammers need better targeting algorithms

I don’t check this blog’s stats much; my other blog is the one I focus more on these days. Since I just published something here, I decided to clean up the spam. Why would you auto-spam a programming blog, in … Continue reading

Posted in General | Tagged | 2 Comments

How to ensure that a number is always round up to the nearest integer

Yes, this is silly. I never used Math.Ceiling before; so I never even knew what it was for. In my use case, I’m sending SMS messages via a third party WCF service. It works well, but in my own WCF … Continue reading

Posted in Programming | Tagged , | Leave a comment

Mailto links with subject and body

This is most probably not news to anybody besides myself, but regardless, I didn’t know that you can create email links including both the subject and body… I was writing something on my other blog and needed to include some … Continue reading

Posted in HTML | Tagged | Leave a comment