·5 min read
How TaskPad replaces its own running exe, and what the checksum covers
The first time I thought about auto-update for TaskPad, the problem sounded impossible. The program that has to be replaced is the program doing the replacing. You cannot copy a new TaskPad.exe over the one that is running, because Windows keeps the file locked.
What you can do is rename it. A running exe cannot be overwritten or deleted, but it can be moved aside, and then the path is free for a new file. That single fact is the entire trick, and the rest of the updater is the careful work of making that swap safe.
- Project
- TaskPad
- Date
- Oct 2026
- Stack
- C#, .NET Framework 4.8, WPF
- Commit
- c03bdda, daa23bf
What broke
TaskPad is meant to be one small exe with no installer required. That makes updating awkward. There is no installer package to re-run and no service that can do the swap from outside. The program has to update itself, in place, while the user may have unsaved text open.
There were two separate problems hiding in that sentence. The first is the lock on the running file. The second is trust: the updater downloads an executable from the internet and then runs it, so a truncated download or the wrong file would be a nasty failure, since it replaces the only copy of the program.
What the code showed
The updater arrived in c03bdda (Oct 2026), and it fits in one file, Updater.cs. It asks the GitHub releases API for the latest release and picks the asset whose URL ends in /TaskPad.exe. That filter matters. The release also has TaskPad-Setup.exe, and the updater must never download the installer by mistake. The same code pulls the hash out of the release notes with a regular expression:
var sha = Regex.Match(json, "SHA-256:\\W*(?<h>[0-9a-fA-F]{64})").Groups["h"].Value;The swap is the part that surprises people:
var exe = ExePath;
var old = exe + ".old";
if (File.Exists(old)) File.Delete(old);
File.Move(exe, old); // allowed while running
try { File.Copy(tmp, exe); }
catch { File.Move(old, exe); throw; }
File.Delete(tmp);Three safety properties come out of those lines. If a previous update left an .old file, it is deleted first so the move cannot fail on a name clash. If the copy of the new exe fails halfway, the catch moves the old exe back and rethrows, so the user is never left with no program. And the failure message is specific. When the exception is UnauthorizedAccessException, the toast says "no write access to the exe folder", which is the real reason a portable copy in a protected folder cannot update.
The .old file is not left lying around for good. Program.cs calls Updater.CleanupOld() on start, which deletes ExePath + ".old" inside a try, so a failed delete never stops the app from starting.
The fix
The part I added after the updater, in daa23bf (Oct 2026), is the installer, and it follows the same philosophy: do not add files. A second program for setup would mean a second build output and a second thing to download and keep in sync. So the installer is the same binary under another name.
public static bool IsSetupLaunch() =>
Path.GetFileNameWithoutExtension(SelfPath).IndexOf("setup", StringComparison.OrdinalIgnoreCase) >= 0 &&
!string.Equals(Path.GetFullPath(SelfPath), Path.GetFullPath(InstalledExe), StringComparison.OrdinalIgnoreCase);If the exe's own file name contains "setup" and it is not already the installed copy, Program.cs starts the setup window instead of the editor, as long as no -- command-line option was passed. That is why a release has two assets, TaskPad-Setup.exe and TaskPad.exe, which are the same program. The installer writes per user under %LOCALAPPDATA%\Programs\TaskPad, which means the updater's rename is always allowed there.
The very first release with the updater, v1.2.0, says in its notes that 1.1.0 and older cannot update themselves, so you download that exe once and updates are automatic from then on. A later commit, 8f74345, made installing in the background the default.
What I would do differently
The checksum is weaker than it sounds, and I want to be exact about how. These are the limits I can see in the code:
- It is optional. The verification sits behind
if (r.Sha != null). If a release's notes have noSHA-256:line, the update goes ahead without any check.build.cmddoes not compute a hash, so I add the line to the notes myself, and the v1.2.0, v1.3.0 and v1.9.4 notes all have one, but nothing forces me to. - It comes from the same place as the file. The hash is read from the release notes of the same GitHub release that hosts the exe. It catches a corrupt or truncated download. It does not protect against someone who can edit that release, because they could change both.
- The exe is unsigned. The release notes say so and tell users to choose "More info" and "Run anyway" in SmartScreen.
If I did it again, I would make the missing hash a failure instead of a skip, and I would publish the hash as its own release asset that the build produces, not a line I copy by hand. A signed exe would be the real answer, but code signing costs money that a small tool does not justify.
I would also test the rollback path on purpose. I read the catch and believe it, but I never forced the copy to fail and watched the old exe come back.
Where this fits
The updater and the installer are the two features that make TaskPad feel like a real application while still being a single 1 MB file. They sit alongside the plain-text layer model and the session restore in the full TaskPad case study, which also covers the comments, deadlines and how the exe embeds its one dependency.
Run the portable exe or the setup file, which are the same program, and read the full project story for the rest of the build.
Download TaskPad#csharp#wpf#updater#windows
Keep reading
Have a project in mind?