C#/VB.Net: Knowing what mode you’re currently executing in

Posted on 24 June 2009

It may not matter when you start your first Hello World application, but when time passes by and your applications become more and more complex, you often want to know where you are when your code is executed. Are you in Debug or Release Build,  are you in Design or User Mode, is the application being debugged? Some answer to these and related questions are trivial, some aren’t at all. Ever tried testing the DesignMode property in a constructor? Ever needed to find out programmatically whether the application currently having the focus in the IDE is Release Build? After reading this article you know that you can’t always rely on the results from the CLR, at best they are vaguely reliable.

The information on how to do these things is scattered at best. After reading this article you’ll know how to robustly test the current running state for the following situations:

  • Design or User Mode
    –> as of yet, there hasn’t been a definitive answer anywhere online, but read on!
  • Debug or Release Build
  • In IDE or outside IDE
  • Having a debugger attached, or not
  • Tracing On or Tracing Off
  • Web application or Forms application
  • How to insert a breakpoint in a release build
  • A service, application, screensaver, dll
  • Checked or Unchecked codeblock
  • Code pre-evaluation mode
  • The state of a UI Web Control through ControlState
  • and more….
  • Download: ready made class with ready made code for ready made answers.

Other Hatties at Under My Hat

Don’t follow the advised on the TechNet, MS Connect and MSDN forums, they are time-consuming and don’t work if you have a newer version of .NET installed like .NET 4.0. Instead, read this and easily fix this hard-to-resolve error by simply changing one registry value. read article

Ever tried to shrink a volume? Ever wondered why you cannot shrink a volume smaller than half its size? Ever wondered what $MFTMirr is all about and what it’s doing in the middle of your drive? Or do you just want to get the biggest available free space and shrink your drive? Then this article is for you — read article

Have you ever received this error using Windows System Backup and Restore Center? Never managed to get rid of it or it mysteriously keeps coming back? Here’s a lightweight and easy solution — read article

 


No responses yet. You could be the first!

Leave a Response

Additional comments powered by BackType

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Copyright © Under My Hat.

Other Recent Hatties (alphabetically)