Here’s a collection of small code samples on different ways to work with the debugger.
Check if debugging
Quickly determine whether the debugger is currently attached.
bool isDebugging = await VS.Debugger.IsDebuggingAsync();
Get the debug mode
Get the specific mode the debugger is in - not debugging, at a breakpoint, or running.
var mode = await VS.Debugger.GetDebugModeAsync();
switch (mode)
{
case Community.VisualStudio.Toolkit.Debugger.DebugMode.NotDebugging:
// Design mode - no debugger attached
break;
case Community.VisualStudio.Toolkit.Debugger.DebugMode.AtBreakpoint:
// Stopped at a breakpoint
break;
case Community.VisualStudio.Toolkit.Debugger.DebugMode.Running:
// Debugger is attached and running
break;
}
Listen for debug mode changes
React when the debugger starts, stops, or hits a breakpoint.
VS.Events.DebuggerEvents.EnterRunMode += () =>
{
// Debugging started or resumed
};
VS.Events.DebuggerEvents.EnterBreakMode += () =>
{
// Hit a breakpoint
};
VS.Events.DebuggerEvents.EnterDesignMode += () =>
{
// Debugging stopped
};
See the Working with events page for all available event types.