Solved

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

Posted on 2011-02-18
2
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Den_HBR earned 500 total points
ID: 34927395
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
ID: 34927545
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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