Solved

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

Posted on 2011-02-18
2
403 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

738 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