Category Archives: Programming

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

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

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

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

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 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

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

How to convert Unicode text to plain ASCII

Let’s say you have a string that was input by somebody out of your control… Maybe it got to you via a call to your web service from a remote client, indirectly via somebody else’s software. And you need to … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to encode or decode a base64 string

This is an absolutely trivial programming task, but one that annoyed me enough to have to write some code to do… I use Filezilla for FTP uploads/downloads at work, but never remember my passwords for FTP sites. Nor do I … Continue reading

Posted in Programming | Tagged | Leave a comment

The curious case of the generic complimentary comment. I hate SPAM!

I published this on my other blog yesterday. But it is related to programming in a way, so now it’s published here too. Recently I received this comment to one of my posts: Hello! I’ve been reading your site for … Continue reading

Posted in Programming | Tagged | Leave a comment

Experimental new C++ operator joke

This is fucking hilarious… Raymond Chen introduced some “new C++ tadpole operators” on his blog. It’s a joke, one that I didn’t get immediately, but what makes it even funnier is that many commenters also didn’t get it. They’re upset … Continue reading

Posted in Programming | Tagged , | Leave a comment

Do NOT cache SSL certificates on the client side – How to post XML asynchronously and read the response using HttpClient in c#

I had one hell of a day yesterday. The evening before, I’d renewed the certificate on a WCF service of ours, because the old one was about to expire. After renewing it, I tested the service to confirm that I … Continue reading

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

Link to: Emulating double dispatch with c#

“Link to” in the title indicates that I am writing about something that somebody else wrote, somebody a lot smarter than myself. Eric Lippert wrote a great post on emulating double dispatch in c#. Actually this is part 3 of … Continue reading

Posted in Programming | Tagged | Leave a comment

Failed to establish a backside connection

We get this error occasionally when using a bank’s web service for AVS-R. (Real-time bank account validation.) Maybe I’m weird but I laugh every time I see that error. I read it as “Cannot find anus.”

Posted in Programming, Work | Tagged | Leave a comment

Zipping a directory and including relative directory paths is non-intuitive with DotNetZip

I recently had to write some code to auto-update an application via an FTP server. It uses home-grown code since ClickOnce is too limiting, and is written in a Windows Forms .NET 3.5 Visual Studio 2010 project. It also had … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to implement IDisposable properly

Every so often I write a class with disposable members, so it needs to implement IDisposable. I always copy and paste from one of my other classes, so I figured it would be useful to share the pattern of IDisposable … Continue reading

Posted in Programming | Tagged , | Leave a comment

SA Mobile Drug Testing… Located somewhere in the tropical Atlantic ocean off the Gulf of Guinea?

This is what happens when you let clueless developers build a website… I was searching for local drug testing options when I found this… Surprising that their top two results for drug testing in Johannesburg are in Cape Town and … Continue reading

Posted in Programming | Tagged | Leave a comment

So funny: I never thought of Bobby Tables this way

I just found this in a comment to Raymond Chen’s latest blog post. I hadn’t seen it before and it’s too funny not to share.

Posted in Programming | Tagged | Leave a comment

A pattern for implementing the == operator in C#

I’ve been neglecting this blog for a while because I have very little time to write here… Every now and then I need to implement the == operator on one of my classes; typically because I want to compare two … Continue reading

Posted in Programming | Tagged , , | Leave a comment

A nice way of handling timesheets

I mentioned a while back that I have started using Toggl for my time sheets… What I did this month, which was the first month I sent the Toggl-based report to my boss, was export a detailed report, then remove … Continue reading

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