?
Solved

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

Posted on 2011-02-18
2
Medium Priority
?
405 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

752 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