Recipe 2.12. Determining if an Application Is Running in the Visual Studio Environment


Problem

Your application needs to respond one way if it is running in the Visual Studio development environment and another way if it is running as a standalone application. For instance, you might want to issue a Stop statement on errors when in the debugging environment but log the errors to a file when running as a standalone application.

Solution

There are a few different ways to determine the running environment of your application, but the simplest is to examine the System.Diagnostics.Debugger. IsAttached flag. If this property is TRue, your application is running in the development environment.

Discussion

The IsAttached property indicates TRue whenever your application is running in a debugger that properly sets the underlying value of this flag. That means that if the flag is true, the program may be running in some environment other than Visual Studio. But if your program is running in some nonVisual Studio debugger, there are probably bigger issues of concern.




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net