How to Check whether the application is running in IDE or as EXE

In our Windows Application, some times we may need to check whether our application is running in IDE or is running as EXE. A typical example would be, we might use Development Server while working in development/debug mode. Once the application is deployed we will be using Live Server. It is very hard if you keep on chaning the server names each time like while dev change the server to development and while live change it back to live. We might make mistakes while switching these servers. To avoid these difficulties we can use the following function to see whether our application is running in IDE or running as standalone EXE.

Module modMain
    Sub Main()
        If IsApplicationRunningInIDE() Then
            Console.WriteLine("I am working on IDE")
        Else
            Console.WriteLine("I am working on standalone EXE")
        End If
    End Sub
    Public Function IsApplicationRunningInIDE() As Boolean
        Return System.Diagnostics.Debugger.IsAttached()
    End Function
End Module

Project Type: Console
Language: VB.Net
Tested with: VS 2008

Incoming search terms:

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>