January 6, 2009  
  You are here:  Blog

QTCommunicationSimplified50.gif


Try Radicomm's Quicktalk, the first enterprise-class Push-To-Talk application for your Motorola/Symbol rugged devices, in your distribution center for free.

Click here to enter the 21st Century.


How To Programmatically Cause a Breakpoint in C# and JavaScript
 
Location: BlogsNetSplore's Blog    
Posted by: Joe Rattz 1/9/2007 8:45:18 PM

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.

Copyright ©2007 Joe Rattz
Permalink |  Trackback

Comments (3)   Add Comment
Re: How To Programmatically Cause a Breakpoint in C#    By Pasi Savolainen on 1/29/2007 9:49:53 AM
Thanks, it helped :)

Re: How To Programmatically Cause a Breakpoint in C#    By vimal on 3/15/2007 9:00:46 AM
GREAT....................

Re: How To Programmatically Cause a Breakpoint in C#    By JF Ouimet on 9/14/2007 9:43:32 AM
Good Stuff...I've been lloking for this for months........ Have a good day !


Your name:
Title:
Comment:
Add Comment   Cancel 
 
Module Border Module Border
My Book

 

Module Border Module Border
Blog Archive
   
    

  Home|Freebies|Blog|Services|Articles|ASP.NET Depot|DotNetNuke Central|Contact Us
  Copyright 2005 Netsplore Terms Of Use Privacy Statement