Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·6 min read

Two TaskPad bugs that failed without a single error on screen

The worst kind of bug in a desktop app is the one where nothing happens. No crash, no dialog, no red text. You start TaskPad and the process is running, but there is no window. Or you click the pencil on a comment and the comment just sits there.

I fixed both in the same short stretch of Oct 2026, and when I read the two diffs side by side, they had the same cause: I had written code to keep TaskPad alive at all costs, and it was very good at keeping failures quiet.

Project
TaskPad
Date
Oct 2026
Stack
C#, WPF
Commit
48b16bf, 25a3d6f

What broke

The first bug lives in session restore. TaskPad remembers windows, tabs, cursor positions and unsaved text, and rebuilds them on start. That feature arrived in 15a5c06 at 21:15 on Oct 4. Forty minutes later I committed 48b16bf, titled "never leave an invisible window after restore". A window could exist inside the app, be counted, be chosen as the target for the next file you opened, and not be on screen.

The second bug showed up the next morning, in the comment editing I had added in efb8e43 (v1.9.2). Clicking the pencil on a message, or double-clicking it, was supposed to swap the text for an edit box. The release notes for v1.9.4 describe what users saw: it "silently did nothing (the edit box failed to open)".

What the code showed

For session restore, the old Restore() walked the saved file line by line. When it hit a win row it created a window, and when it hit grp rows it filled the window with tabs. The window constructor registers itself with the workspace, and Show() was only called later, in a finishing step. In between sat a catch block:

csharp
catch
{
    return Workspace.Windows.Count > 0;
}

If anything threw after a window was created and before it was shown, that catch said "yes, restore worked", because a window existed in the list. The caller in Program.cs then took Workspace.LastActive as its window, opened your files in it and activated it, and skipped the normal fresh window. That window was never shown. Worse, Program.cs picked the target for a second launch with Workspace.LastActive ?? Workspace.Windows[0], so the next file you opened could be sent to the ghost.

There was a second way to get an invisible window, and it was not an exception at all. The saved position was used as is, with a default of 100. A window saved on a monitor you later unplugged could be restored at coordinates no screen covers.

The comment bug was one line. To turn a message into an edit box, I assigned into the panel's children by index:

csharp
holder.Children[holder.Children.IndexOf(body)] = box;

The comment I left in the fix says a panel slot cannot be overwritten in place and that WPF throws. I did not reproduce the exception type for this write-up, so I will stay with what the code comment and the release note say. What I can show is why it looked like nothing. Program.cs has, from the very first commit, this handler:

csharp
app.DispatcherUnhandledException += (s, e) =>
{
    // keep the app (and unsaved text) alive; log for bug reports
    try { File.AppendAllText(Path.Combine(Path.GetTempPath(), "TaskPad-error.log"), ...); } catch { }
    e.Handled = true;
};

I wrote it so a stray exception would never cost anyone unsaved text, and for that purpose it is right. But a click handler that throws would go to a log file in the temp folder, and the user sees a button that does nothing. The safety net and the silence were the same line.

The fix

For restore, 48b16bf changed the shape of the code instead of patching the catch. The file is parsed into rows first. Documents load. Then, per window, the tabs are worked out before any window exists:

csharp
if (groupTabs.All(t => t.Count == 0)) continue;   // nothing to show: don't create a window at all

Creating the window moved into its own method with its own try and catch. On failure it logs, detaches the tabs it added and removes the window from the workspace instead of leaving it behind. A final sweep removes any window that is not visible and disposes documents nobody shows. The position is checked with an OnScreen test and falls back to centred when no screen covers it.

  1. 01

    Parse

    rows read first, documents loaded

  2. 02

    Work out tabs

    per window, before it exists

  3. 03

    Skip empty

    no tabs, no window

  4. 04

    Build and show

    its own try and catch, failures logged

  5. 05

    Sweep

    invisible windows removed, orphan documents disposed

Figure 1. Session restore after 48b16bf.

Session.Save got the matching guard, if (!w.IsVisible || ...) continue;, so an invisible window cannot be written into the next session. The second-launch code now ignores invisible windows too. It shipped as v1.3.5.

For comments, 25a3d6f (Oct 2026) takes the text out of the panel and puts the box in at the same position:

csharp
int at = holder.Children.IndexOf(body);
holder.Children.RemoveAt(at);
holder.Children.Insert(at, box);

The same commit added a copy button and a right-click menu with Copy, Edit and Delete, and it shipped as v1.9.4.

What I would do differently

I would make the global handler louder in a way that costs nothing. It can keep the app alive and still tell the user, with a small toast that says something went wrong and where the log is. Silence is a fine default for a crash I cannot prevent. It is a poor default for a click that failed.

For session restore I would have built it the way the fix does from the start: decide what can be shown, then create only that. My first version created things optimistically and cleaned up in a finishing step, and any exception between the two steps skipped the cleanup. Creating a window and showing it should be one operation that either completes or leaves nothing.

I also never wrote a test that restores a session whose saved window has no tabs, or one saved at coordinates off every screen. Both cases are cheap to describe and were exactly where the bug lived.

Where this fits

These two fixes are small, but they show how much of a polished app is deciding what happens when something goes wrong. Restoring your work after a restart is the feature I trust least to get wrong, because it handles your unsaved text. The full TaskPad case study puts them next to the rest of the build: the plain-text layer model, the updater and the single exe.

Close it with unsaved text and reopen it to see session restore, or read the full project story for how the editor was built.

Download TaskPad

#wpf#csharp#error-handling#debugging

Keep reading

Have a project in mind?