Header BackgroundHeader BackgroundHeader BackgroundHeader BackgroundSebastian

Setting Up the Project Foundations

The heart of WslDock is a clean event loop that responds directly to Windows messages. Rather than burdening the CPU with manual polling cycles, the application leverages native operating system functionality. This loop forms the backbone for managing process handles, configuration changes, and user interactions.

Three Technical Pillars

For the technical implementation, three pillars were crucial:

  • The Window Handle (HWND): Although WslDock has no visible user interface, a window is registered in the background to receive tray icon events and system messages (such as DPI changes).
  • Dynamic Icons via Resource Files: Unlike StayAwake’s GDI-generated icons, WslDock uses pre-designed icon resources for its three states: inactive, active, and active+SSH. Each state has multi-resolution icons (32×32, 48×48, 64×64) to ensure crisp rendering at any DPI setting.
  • Single Instance Mutex: To prevent conflicts between multiple instances, a named mutex ensures that only one process is active at any given time. When a new version is launched, the running instance is cleanly terminated via WM_CLOSE before the new one takes over.

The Event Loop Architecture

The main loop uses MsgWaitForMultipleObjects to efficiently wait for:

  • Configuration file changes (via FindFirstChangeNotificationW)
  • Process state changes (WSL and SSH process handles)
  • User input (tray icon clicks, menu selections)

This approach ensures zero CPU usage while idle, yet instant responsiveness to any event.


Using MsgWaitForMultipleObjects in the event loop represents the pinnacle of Windows programming. It allows the tool to consume literally zero percent CPU load while idle, yet remain instantly responsive to user input or configuration changes. Combined with the file system watcher for config hot-reload, WslDock achieves a reactive architecture without complex frameworks.

AI Insights: The Elegance of the Win32 API