Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·5 min read

TaskPad setup quits the running copy over its own named pipe, not with Kill

The TaskPad installer copies a new exe over the old one, and that is where it used to stop being polite. If TaskPad was open, the update applied "on its next start", which in practice meant the user kept working in the old build with no hint that a new one sat on disk. I wanted setup to close the running copy, install, and reopen it with every tab and unsaved line still there. The part that took design was the closing.

Project
TaskPad
Date
Oct 2026
Stack
C#, WPF, Named pipes
Commit
d19b3cd

Why not just kill the process

The obvious fix is Process.Kill() on every TaskPad process before copying the file. It works, and it loses data: TaskPad keeps unsaved text in a session, and the quit path saves that session explicitly before closing. A killed process never reaches that code. Since the whole point of the installer is that an update should be uneventful, a design that can eat someone's draft was not acceptable.

So the first requirement became: ask the app to quit, in a way that is safe by construction, and treat killing as a last resort.

Reusing the pipe the app already has

TaskPad is a single-instance app. Opening a file from Explorer while it runs hands the path to the existing process through a named pipe whose name is derived from the user name:

csharp
public static readonly string InstanceId =
    "TaskPad-" + Environment.UserName +
    (Environment.GetEnvironmentVariable("TASKPAD_INSTANCE") ?? "");

That field used to be private. The commit makes it public, because the installer is the second client of the same pipe. CloseRunning connects and writes a magic message instead of file paths:

csharp
public const string QuitMessage = "--quit-all";

using (var c = new NamedPipeClientStream(".", Program.InstanceId, PipeDirection.Out))
{
    c.Connect(1500);
    var data = Encoding.UTF8.GetBytes(QuitMessage);
    c.Write(data, 0, data.Length);
}

On the receiving side the pipe handler already splits incoming text into paths. One line was added before that split:

csharp
if (paths.Length == 1 && paths[0] == Installer.QuitMessage) { Updater.QuitAll(); return; }

A message like that cannot be mistaken for a real file, since no path on disk is literally --quit-all. That is the whole protocol, and it needed no new listener.

What "quit the safe way" means

QuitAll is the piece that makes the reinstall invisible:

csharp
public static void QuitAll()
{
    if (Session.Enabled)
    {
        Session.Save();
        Session.Quitting = true;
    }
    foreach (var w in Workspace.Windows.ToList()) w.Close();
    if (Workspace.Windows.Count > 0) { Session.Quitting = false; return; }
    Application.Current.Shutdown();
}

It saves the session first, then closes every window with Session.Quitting set, so a window closing does not stop to ask whether to save. The code comment states the effect: files saved, unsaved text kept in the session, no prompts. If any window is still open afterwards, the flag is reset and the method returns without shutting down, so a half-quit never leaves the app in a state where the next real close skips its prompt.

When the new exe starts, LaunchInstalled() runs it with the same working directory, and the existing restore logic brings back every tab.

The fallback ladder

The pipe only reaches the main copy. Someone may also run a separate portable copy, which has its own InstanceId suffix or none at all. So CloseRunning goes through steps:

csharp
// 1) pipe quit request to the main copy
Thread.Sleep(800);
// 2) other copies: ask their windows to close
foreach (var p in Running()) { try { p.CloseMainWindow(); } catch { } }
while (DateTime.Now < until && Running().Count > 0) Thread.Sleep(250);
if (Running().Count == 0) return true;
if (!force) return false;
foreach (var p in Running()) { try { p.Kill(); p.WaitForExit(3000); } catch { } }

Running() lists TaskPad processes by name, excluding the setup's own process id. That exclusion matters: the setup is itself a copy of the same exe, and without it the loop would wait for itself.

Who gets to force

The two entry points differ in how they treat the last rung.

The interactive installer calls CloseRunning(12000, force: false). If something is still alive after 12 seconds, a message box says that some windows did not close, maybe because they are waiting for an answer to a question, and asks whether to force them, warning that unsaved text in them may be lost. Only a Yes proceeds to CloseRunning(1000, force: true).

The silent path, --install --quiet, has no one to ask. It records whether TaskPad was running, calls CloseRunning(15000, force: true), installs, and relaunches only if something had been running. A silent update is the case where background updates matter most, and a hung old process would otherwise block the file replacement.

The installer also shows a short highlighted note, "TaskPad is open right now", or a count of copies, with a checkbox to close and reopen. It is on by default.

What I would check next

I did not measure how often the pipe request alone is enough versus how often the fallback fires, and the repo has no counter for it, so I cannot say. The 12 and 15 second limits are choices, not results.

What I take from it is simpler: when an app already has an IPC channel, use it for lifecycle messages as well. The quit request goes through the same code path that handles opening a file, so it is as well exercised as that path is, and the installer never needs to know how the app saves its state.

#csharp#wpf#named-pipes#installer#windows

Keep reading

Have a project in mind?