Now would probably be a good time to point out that when I first started creating articles for NetSplore, my intent was not only to share information with others, but to share it with myself...in the future! I can't tell you how many times I have had to go scrambling trying to figure out what code did something I needed to do again. So, I thought that if there was something I was having trouble remembering how to accomplish, others may have the same problem, and I should create an article.
I explain all that as a disclaimer as to why this article seems so trivial. Frankly, I can never seem to remember how to programmtically trigger a breakpoint in my code. This article tells how.
C#
Add the following code to the location you want to break, and it's just that simple:
#if DEBUG
System.Diagnostics.Debugger.Break();
#endif
That's all there is to it. If you aren't going to leave the statement in the code, you don't need the #if Debug part. But if you run the program compiled by the release configuration without it, you will have trouble.
JavaScript
To programmatically cause cause a breakpoint in JavaScript in Visual Studio, add a debugger statement. A terminating semi-colon isn't even necessary:
function MyCustomValidator(ctl, args)
{
debugger
var grid = igtbl_getGridById("MyGrid");
args.IsValid = grid != null;
}
I am guessing that this will not work for most other (than Visual Studio) JavaScript development environments. If you know what to do for other environments, please post a comment explaining the environment and how to make the debugger programmatically break and I will add it to this post.
I hope this simple article helps someone.