Am I running from a development environment?

  • Thread starter Thread starter Turtle
  • Start date Start date
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
 
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()
 
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
 
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
 
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
 
<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
 
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
 
Back
Top