Solved

VB.NET - Way to disable some code when running in the Visual Studio editor

Posted on 2011-02-18
2
398 Views
Last Modified: 2012-05-11
Hi,
I have an app that runs a timer continuously to update the status bar of my application with the details of the currently selected customer record and also the details of an additional record in a separate pane. I want the timer running as it picks up when a new sub record is added and allows me to display messages that clear after a few seconds and revert back to the normal status message.  

It works really well except when I am debugging, as when stepping the code it keeps flicking back to the routine that does the updated status bar and then returns back to the code I am stepping. It's not the end of the World, but it gets very annoying when you are stepping through some complex code and don't want to lose your concentration.

I tried putting in a conditional compilation:

#If Not Debug Then
    Private Sub tmrUpdateStatusBar_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUpdateStatusBar.Tick
        SBar1.Panels(0).Text = "Client ID is: " & lblClientIDValue.Text & " Details: " & CurrentClientDetails & "."
    End Sub
#End If

I now realise that this mechanism just changes what gets compiled depending on the project configuration is debug or release not whether I am debugging the code by stepping in the editor.

Is there another code constructy that I can put in that effectively says, "don't run this if I am stepping the code in the editor" but do run it if you are running without stepping?

Any help appreciared.

Siv
0
Comment
Question by:Siv
2 Comments
 
LVL 8

Accepted Solution

by:
Den_HBR earned 500 total points
Comment Utility
Do you mean something like this?

 
If Debugger.IsAttached Then
            tmrUpdateStatusBar.Enabled = False
        Else
            SBar1.Panels(0).Text = "Client ID is: " & lblClientIDValue.Text & " Details: " & CurrentClientDetails & "."
        End If

Open in new window

This way you will only get 1 time to the timer.tick while debugging

You could also put below in a form.load (or something)
 
If Debugger.IsAttached Then
    tmrUpdateStatusBar.Enabled = False
End If

Open in new window

0
 

Author Closing Comment

by:Siv
Comment Utility
Den_HBR,

Thanks a lot, this did the trick and stops the timer running when running in the ide.

I knew there must be some way of doing it just couldn't find it.

Siv
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Template or Software to write user guide 2 29
GridDataView 6 44
Custom auto number 6 51
Hide Tab Page 3 18
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now