Visual Studio 2026 Debugger Detection Failure
This is a submission for DEV's Summer Bug Smash: Smash Stories powered by Sentry . Background I was building a Coding Activity Tracker to give me realistic timing for how long I actually spend coding — typing, reading, debugging, idle, everything. For that to work, it needed to know when Visual Studio was debugging anything , because breakpoints completely change how an app behaves. Running the tracker standalone meant it had to detect external debugging sessions. Debugger.IsAttached only detects debugging of the current process , so standalone mode always reported “no debugger,” even when Visual Studio was actively debugging another project. That single limitation broke the entire purpose of the tracker. The tracker had to detect debugging even when it wasn’t the app being debugged . What Was Tried Once it became obvious that Debugger.IsAttached was useless for standalone mode, I started trying every simple, reasonable approach that should have worked but didn’t. Parent‑process tracing int parentPid = GetParentProcessId(targetProcess); Fails because Visual Studio doesn’t always launch the debug target. Sometimes the user launches it manually. Sometimes VS attaches to an already‑running process. WMI queries var query = new ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE ProcessId = " + pid); Slow, stale, inconsistent, and occasionally wrong. Not usable in real‑time tracking. Process‑tree walking var children = GetChildProcesses(vsProcess.Id); Visual Studio’s process tree is chaos. Helper processes spawn and die constantly. None reliably indicate debugging. Handle inspection var handles = GetProcessHandles(targetProcess); There is no stable “debugging handle” pattern. Different projects produce different handle sets. Thread‑freeze detection bool frozen = targetProcess.Threads.Cast<ProcessThread>() .Any(t => t.ThreadState == ThreadState.Wait); Breakpoints freeze the debugger, not the tracker. And threads freeze for normal reasons too. Tons of false positiv