Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6946039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:30:50+00:00 2026-05-27T13:30:50+00:00

I’m using Visual Studio 2008 on C# code. I would like to only break

  • 0

I’m using Visual Studio 2008 on C# code.

I would like to only break on a breakpoint if another breakpoint has been hit (and broken upon.) Is there a way of doing that?

I would imagine as a subproblem it would be nice to get access to the information that the debugger has.

The rationale for this is I’m interested in only breaking on a certain breakpoint given a certain callstack (and at a certain point in the execution of one of those functions in the callstack). Perhaps I should be using the callstack instead? Another reason is it would be interesting to have programmatic access to the stuff that the debugger knows about.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:30:51+00:00Added an answer on May 27, 2026 at 1:30 pm

    Using local variable

    The easiest way to create such a conditional breakpoint would be to create a new thread-static variable (or just static if it should be global). Suppose that our code looks as follows:

    class Program
    {
    #if DEBUG
        [ThreadStatic]
        static int breakVariable = 0;
    #endif
    
        static void Main(string[] args)
        {
            TestMethod2();
    
            TestMethod1();
            TestMethod2();
    
            TestMethod2();
    
            TestMethod1();
            TestMethod2();
        }
    
        static void TestMethod1()
        {
            Console.WriteLine("test1");
        }
    
        static void TestMethod2()
        {
            Console.WriteLine("test2");
        }
    }
    

    Let’s now assume that you set a breakpoint1 on Console.WriteLine("test1"); and breakpoint2 on Console.WriteLine("test2");. You would like to break at the breakpoint2 only when the breakpoint1 was hit 2 times. In this case you would need to set Hit Count... property of the breapoint1 to break when the hit count is equal to 2. Then in the When Hit... property check Print a message and in the textbox type: {breakVariable = 1}:

    when break

    Then set the property Condition... of the breakpoint2 to breakVariable == 1 and check Is true:

    condition

    If you would like the breakpoint2 to become inactive after being hit you may again use When Hit... property setting its Print a message value to {breakVariable=0}.

    Using macro

    This approach is much harder especially if you don’t like VBA (like me:) ) but you may be interested as it does not require any changes in the application code. Let’s define two macros:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    
    Public Module Module1
    
        Public Sub SetMyBreakpoint()
            Dim bps As EnvDTE.Breakpoints
            bps = DTE.Debugger.Breakpoints.Add(File:="C:\MyProject\ConsoleApplication1\Program.cs", _
                                               Line:=25)
            Dim bp As EnvDTE80.Breakpoint2
            For Each bp In bps
                bp.Tag = "mytag"
                ' Add this line only if you want the breakpoint to be removed on hit
                ' Although I don't know why - it does not always worked :(
                bp.Macro = "Macros.MyMacros.Module1.RemoveMyBreakpoint"
            Next
        End Sub
    
        Public Sub RemoveMyBreakpoint()
            Dim bp As EnvDTE.Breakpoint
            For Each bp In DTE.Debugger.Breakpoints
                If (bp.Tag = "mytag") Then
                    bp.Delete()
                End If
            Next
        End Sub
    End Module
    

    Now for the breakpoint1 you still want to set the Hit Count... property as previously but now in the When Hit... property instead of checking Print a message check Run a macro and select the SetMyBreakpoint procedure. It’s very important that you provide the full path of the code file in the Breakpoints.Add method and the correct line (you may check the API to find other ways to set a breakpoint, like on the function instead a code file). One small caveat here – I observed that the automatic removal of the second breakpoint does not always worked – but maybe it was my Visual Studio.

    Using call stack

    You may again use the Condition property of the breakpoint – have a look at this question to find some details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.