.NET Tips and Tricks

Blog archive

Write to Visual Studio's Output Window on Your Breakpoints

I can't tell you the number of times I've put a breakpoint inside a loop so that I could stop each time I go through the loop and check the value of some variable or property. Unfortunately, by the third or fourth trip through the loop I've forgotten what the values were on my first trip through the loop.

If that's your life also, your best choice is to use a tracepoint which will write the information you're interested in to the output window. With a tracepoint, you can review the values you're interested in after the loop finishes. You can even just let your code run, rather than stopping on the line you're interested in.

Setting a tracepoint varies from one version of Visual Studio to another. The easiest way is to set a breakpoint and then right click on the dot in the margin that marks your breakpoint. When the popup menu appears, either select the When Hit choice (in earlier versions of Visual Studio) or the Actions choice (in later versions). Those choices will display the dialog that lets you define your tracepoint.

In that dialog you can enter the message you want written to the output window, enclosing any variables you want displayed in curly braces ({ }). Something like "The counter is {i} and the Customer's age is {cust.age}" will work, for example.

If you'd rather not stop on the breakpoint, make sure the Continue Execution checkbox at the bottom of the dialog is checked. You can do a quick visual check to see if you'll be stopping on the line: If you still have a dot in the margin, it's still a breakpoint and you'll stop every time the line is hit; if you have a diamond in the margin, it's a tracepoint and will just write out your message without pausing.

Now run your application and, after it finishes, look in the output window to see how your data changed over time.

Posted by Peter Vogel on 06/23/2016


comments powered by Disqus

Featured

  • Vibe Coding Pioneer Advises 'Tight Leash' to Rein In AI BS

    Andrej Karpathy, who started the whole "vibe coding" thing to describe AI-drive software development, is now warning developers to keep tight control of their "new over-eager junior intern savant with encyclopedic knowledge of software, but who also bull* you all the time, has an over-abundance of courage and shows little to no taste for good code."

  • Microsoft Unifies Cloud and AI Development with .NET Aspire and AI Template Updates

    Microsoft announced the availability of .NET Aspire 9.2 and the second preview of the .NET AI Chat Web App template, highlighting new capabilities that bring cloud-native orchestration and AI integration closer together in the .NET ecosystem.

  • Hands On with Microsoft's AI Playground in a Windows App

    Microsoft reintroduced the AI Dev Gallery, a Windows application that serves as a comprehensive playground for AI development using .NET. It simplifies AI development with .NET through interactive samples, easy model downloads, and exportable source code.

  • Vibe Coding Advances in Visual Studio 2022 Previews

    Preview 3 features next edit suggestions -- or tab, tab, tab coding -- following previous previews of GPT-4o code completions and assorted Copilot enhancements.

  • Mastering Modern JavaScript

    Master the latest features of modern JavaScript in a hands-on workshop covering clean code techniques, async programming, templating, and full-stack development with Node.js.

Subscribe on YouTube

Upcoming Training Events

0 AM
Visual Studio Live! San Diego
September 8-12, 2025
Live! 360 Orlando
November 16-21, 2025
Cloud & Containers Live! Orlando
November 16-21, 2025
Data Platform Live! Orlando
November 16-21, 2025
Visual Studio Live! Orlando
November 16-21, 2025