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
Solved

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

Posted on 2011-02-18
2
401 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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
SSRS troubles 4 68
VB.Net/LINQ: ".Contains" condition not finding existing result in MSSQL 16 41
Calculate number of nights between two dates 5 53
Very Large data in MYSQL 7 73
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

790 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