Is there a way to enter debug mode when a certain condition is met?
For example let’s say I would want to enter debug mode on the line on which i == 1 becomes true:
using System;
namespace ConditionalDebug
{
public class Program
{
public static void Main(string[] args)
{
var r = new Random();
var i = r.Next(2);
i += r.Next(2);
i += r.Next(2);
i += r.Next(2);
i += r.Next(2);
i = 1;
Console.WriteLine(i);
}
}
}
I know it is possible to set conditional breakpoints like:

But of course I couldn’t use that since I would have to add a conditional breakpoint for each line in the code where the condition value might get changed and that would get very messy in a real application.
So, is there a way to globally set the condition i == 1 so that the debugger will break on the line on which the condition is met?
Thanks for your help!
The short answer is ‘No’
The long answer is ‘Not really, but kinda’. There are things you can do to get close to the behaviour you want.