views:

78

answers:

2

Consider i have a window Application,developed in Visual Studio 2005, having a button.

I need to use "Run to cursor"/Debug when the button is Clicked Third time(or some nth time) and not First time. How can i do this.?

Consider this being a sample code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace breakPoint
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                textBox1.Text += "hi ";
                textBox2.Text += "hello ";
                textBox3.Text += "bye ";
            }

        }
    }
}

I need to insert break point at "textBox1.Text" line when i click the button nth time.

+7  A: 

You can't use Run to Cursor for this but you can use a break point.

  1. Place a break point on the line in question
  2. Right click on the breakpoint red circle
  3. Select Hit Count
  4. Change the combo box ot "break when hit count is equal to"
  5. Change the number 1 to your value N
  6. Hit OK

The breakpoint will now only stop on the Nth time it's hit.

EDIT

Responding to clarification. Then put the breakpoint on the actual function declaration itself. That will only be executed once per click. You can then step into the loop and hit the place you want.

JaredPar
i have it inside a for loop. So its not working. When its outside the loop its working fine.
pragadheesh
The breakpoint gets activated when the count i.e variable 'i' becomes 2 in the first button click itself.
pragadheesh