Am I running from a development environment?

T

Turtle

I'm developing a Windows Forms application, where I would like to handle
errors differently depending on whether I'm running from a development
environment or directly from a .EXE file.
Any ideas how I can determine this?

- Turtle
 
G

Guest

I'm developing a Windows Forms application, where I would like to handle
errors differently depending on whether I'm running from a development
environment or directly from a .EXE file.
Any ideas how I can determine this?

Diagnostics.Debugger.IsAttached()
 
M

Mattias Sjögren

Any ideas how I can determine this?

You can't really. But you can check if there's a debugger attached to
the process with System.Diagnostics.Debugger.IsAttached.


Mattias
 
T

The Grim Reaper

Yeah you can! This was converted years ago, from some even older VB6 code..
but it still works!

Public Function AreWeInTheIDE() As Boolean
' Determine if we're in the IDE or not
Dim vInDevelopment As Boolean
System.Diagnostics.Debug.Assert(CheckIDE(vInDevelopment), String.Empty)
Return vInDevelopment
End Function

Private Function CheckIDE(ByRef pStatus As Boolean) As Boolean
' This function is only called in the IDE - so return true to confirm
this is development
pStatus = True
Return True
End Function

____________________________________________
The Grim Reaper
 
M

Mattias Sjögren

Yeah you can! This was converted years ago, from some even older VB6 code..
but it still works!

Debug.Assert has the Conditional("DEBUG") attribute on it. So
AreWeInTheIDE will return True whenever the DEBUG conditional
compilation symbol is defined, and False otherwise. That has nothing
to do with whether or not you're running the application from the IDE
or not.


Mattias
 
T

The Grim Reaper

<insert rude words here>

I assumed that cos I converted it so long ago, that I'd tested it too...
oopps.

Thanks for pointing that out. Have now tested it and feel suitable
sheepish.

_____________________________
The Grim Reaper
 
T

Turtle

Many thanks to all of you!

Mattias Sjögren said:
You can't really. But you can check if there's a debugger attached to
the process with System.Diagnostics.Debugger.IsAttached.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top