·5 min read
TaskPad reminders: a time window instead of a flag, and a five-way hotkey fallback
The simplest reminder code I could have written is a timer that asks "which deadlines are overdue?" every few seconds. It would also ring for every old overdue task each time the app starts, and again after every wake from sleep. TaskPad's reminder loop is built around a different question, and the global hotkey next to it has its own small trap: another program may already own the key you want.
- Project
- TaskPad
- Date
- Oct 2026
- Stack
- C#, WPF, Win32 (RegisterHotKey)
- Commit
- ac57b94
What the commit added
Commit ac57b94 added an Agenda tab (every task with a deadline, collected from open notes, the open folders and the Inbox), a tray icon, Windows notifications and a quick-capture box. The tray code carries one rule from its summary comment: with the tray on, closing the last window keeps TaskPad running quietly so reminders keep working. Start with Windows writes "<path to exe>" --tray into the per-user Run key, so after a reboot it comes up without a window.
The window, not the flag
Reminders run from a 30 second tick. This is the whole check:
foreach (var e in items.Where(x => !x.Done))
{
var key = (e.Path ?? e.Name) + "|" + e.Text + "|" + e.When.ToString("o");
if (e.When > _lastTick && e.When <= now && Notified.Add(key + "|due"))
{
Notify("Due now", e.Text + " · " + e.Name, e);
rang = true;
}
else if (e.HasTime && e.When - TimeSpan.FromMinutes(15) > _lastTick
&& e.When - TimeSpan.FromMinutes(15) <= now && Notified.Add(key + "|soon"))
{
Notify("Due in 15 minutes", e.Text + " · " + e.Name, e);
rang = true;
}
}
if (rang) Sound.Play(Sound.Fx.Reminder);
_lastTick = now;A deadline rings only if its time is after the previous tick and not after the current one. _lastTick starts at the moment the process starts, so a task that was already overdue when TaskPad launched falls outside every window and never notifies. For the same reason, if the machine sleeps for three hours and wakes up, the next tick covers the whole gap once, and a deadline inside it rings once. Nothing is replayed.
The Notified set is a second guard. It is a HashSet<string> in memory, with a key built from the file path (or note name), the task text and the exact deadline in round-trip format. If the same window is evaluated twice, or the Agenda is rebuilt in between, Add returns false and the second notification never appears. The suffixes |due and |soon keep the two kinds of notification separate, so a task gets at most one of each.
The trade-offs are visible in the code, and I would rather list them than pretend there are none:
- The set lives only in memory, so it is empty after a restart. That is safe because of the window: a restart moves
_lastTickforward, so earlier deadlines are outside it. - A deadline that passed while TaskPad was not running is never announced. The Agenda still lists it, which is where an overdue task belongs.
- Editing a task's text or time changes its key, so an edited deadline can ring again. I consider that correct: it is a new deadline.
- The check only covers tasks with a time for the 15 minute warning. A date-only deadline has no "soon", because there is no moment to count back from.
Collecting the items is wrapped in a try that simply returns on failure, so a note being written at that instant costs one skipped tick, not a crash in a background timer. That fits the rest of the design, since a missed tick is only half a minute of delay.
The hotkey
Quick capture is a spotlight-style box that appends a line to Inbox.task from anywhere. It needs a global hotkey, and RegisterHotKey fails when another program already owns the combination. Win+Alt+T is deliberately not first in the list, and a comment in the code records why: it is taken by Xbox Game Bar on many PCs. So the code keeps a list and takes the first one that registers:
var options = new (uint Mods, uint Key, string Text)[]
{
(MOD_WIN | MOD_ALT, 0x4E, "Win+Alt+N"),
(MOD_CONTROL | MOD_ALT, 0x4E, "Ctrl+Alt+N"),
(MOD_CONTROL | MOD_ALT, 0x20, "Ctrl+Alt+Space"),
(MOD_WIN | MOD_ALT, VK_T, "Win+Alt+T"),
(MOD_CONTROL | MOD_ALT | 4, VK_T, "Ctrl+Shift+Alt+T"),
};
foreach (var o in options)
if (RegisterHotKey(_hotkeyWindow.Handle, HotkeyId, o.Mods | MOD_NOREPEAT, o.Key)) { HotkeyText = o.Text; break; }Two details matter. MOD_NOREPEAT stops a held key from opening the box over and over. And the text of the winning combination is stored in HotkeyText so the menu can show the user what actually got registered, instead of a shortcut printed in the docs that may not be the one in force. If all five fail, the code logs the Win32 error and carries on without a hotkey.
The hotkey is received on a zero-size HwndSource, so no visible window is involved, and its hook handles WM_HOTKEY and opens the box.
Lesson
For anything that notifies, decide what the unit of "new" is before writing the loop. A flag on each task needs persistence and cleanup. A time window needs one DateTime and an honest answer about what happens when the app was not running. For shortcuts, treat registration as a request that can be refused, keep an ordered list, and show the user the one that won. I did not measure the cost of the 30 second tick; the items are read through a cache keyed by write time in the Agenda code, which is why I was comfortable running it on a timer.
#csharp#wpf#win32#notifications#design
Keep reading
Have a project in mind?