Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Determining when application is running in debug mode

Determining when application is running in debug mode

Scheduled Pinned Locked Moved C#
visual-studioquestioncsharphostingdebugging
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theFrenchHornet
    wrote on last edited by
    #1

    As far as I can tell, if the Visual Studio hosting process is enabled, then when Start Debugging is selected, no new process is added. If you look at the Task Manager Processes tab, you see xxx.vshost.exe when the IDE is open and still only see that when the application is being run (debugged). The place where you _can_ tell a difference is the Applications tab of the Task Manager. I know how to get the list of processes that show up in the task manager Processes tab. How do I get the list of applications that show up in the Applications tab? Thanks ...

    L M T 3 Replies Last reply
    0
    • T theFrenchHornet

      As far as I can tell, if the Visual Studio hosting process is enabled, then when Start Debugging is selected, no new process is added. If you look at the Task Manager Processes tab, you see xxx.vshost.exe when the IDE is open and still only see that when the application is being run (debugged). The place where you _can_ tell a difference is the Applications tab of the Task Manager. I know how to get the list of processes that show up in the task manager Processes tab. How do I get the list of applications that show up in the Applications tab? Thanks ...

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I am not sure what you want, a debug build of your app can be running either with or without vshosting, but both cases are "debugging". If you want your app to know whether it is running through vshost or directly, have it search Environment.CommandLine for ".vshost." If you want your app to know whether it is a debug or a release build, the easiest way is to conditionally include/exclude some code using #if DEBUG ... #endif Hope this helps. :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      T 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I am not sure what you want, a debug build of your app can be running either with or without vshosting, but both cases are "debugging". If you want your app to know whether it is running through vshost or directly, have it search Environment.CommandLine for ".vshost." If you want your app to know whether it is a debug or a release build, the easiest way is to conditionally include/exclude some code using #if DEBUG ... #endif Hope this helps. :)

        Luc Pattyn [My Articles] [Forum Guidelines]

        T Offline
        T Offline
        theFrenchHornet
        wrote on last edited by
        #3

        Thanks for the suggestions - don't think they will solve this problem. Yes, both cases are "debugging" but I specified I was interested in the case where vshosting is enabled because I can detect what I need to know in the case where it isn't. Environment.CommandLine won't tell me because it is another instance of the application that needs to know. I do not need to determine between debug and release versions. What will tell me what I need to know sits in the Applications tab of the Task Manager - do you know how to access that info? The other way I see is if there is some property of the vshost process which indicates whether it is running the application currently or not. Seemed easier to me if I could access the Applications tab of the task manager.

        L 1 Reply Last reply
        0
        • T theFrenchHornet

          Thanks for the suggestions - don't think they will solve this problem. Yes, both cases are "debugging" but I specified I was interested in the case where vshosting is enabled because I can detect what I need to know in the case where it isn't. Environment.CommandLine won't tell me because it is another instance of the application that needs to know. I do not need to determine between debug and release versions. What will tell me what I need to know sits in the Applications tab of the Task Manager - do you know how to access that info? The other way I see is if there is some property of the vshost process which indicates whether it is running the application currently or not. Seemed easier to me if I could access the Applications tab of the task manager.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, getting the list of items shown by "app" tab in Task Manager is complex; it entails finding the right window (i.e. knowing the names of the windows in its hierarchy), then sending some LVM_... messages to the listview. It must be similar to enumerating the notify icons in the system tray, and the icons on the desktop. Each of these can be found in several CodeProject articles. I dont think reading that list is a very good idea; it is complex and the names you would get are Window titles, which does not necessarily correlate well with the process names... Using TaskInfo I noticed the vshost.exe process has quite different characteristics (CPU time, working set, number of windows, ...) when comparing an idle state with an active debug state. So if what you want to figure out is whether something is being handled by vshost, I suggest you get hold of its PID (using Process class), then do a P/Invoke to either get its main window title, or to enumerate all its windows (zero when not active). :)

          Luc Pattyn [My Articles] [Forum Guidelines]

          T 2 Replies Last reply
          0
          • L Luc Pattyn

            Hi, getting the list of items shown by "app" tab in Task Manager is complex; it entails finding the right window (i.e. knowing the names of the windows in its hierarchy), then sending some LVM_... messages to the listview. It must be similar to enumerating the notify icons in the system tray, and the icons on the desktop. Each of these can be found in several CodeProject articles. I dont think reading that list is a very good idea; it is complex and the names you would get are Window titles, which does not necessarily correlate well with the process names... Using TaskInfo I noticed the vshost.exe process has quite different characteristics (CPU time, working set, number of windows, ...) when comparing an idle state with an active debug state. So if what you want to figure out is whether something is being handled by vshost, I suggest you get hold of its PID (using Process class), then do a P/Invoke to either get its main window title, or to enumerate all its windows (zero when not active). :)

            Luc Pattyn [My Articles] [Forum Guidelines]

            T Offline
            T Offline
            theFrenchHornet
            wrote on last edited by
            #5

            The window title would work fine - doesn't need to correlate with the process name. I was searching for task manager before - I'll try your system tray idea - do seem to remember seeing some items on that. Will also look into your idea of vshost characteristics - thanks.

            L 1 Reply Last reply
            0
            • T theFrenchHornet

              The window title would work fine - doesn't need to correlate with the process name. I was searching for task manager before - I'll try your system tray idea - do seem to remember seeing some items on that. Will also look into your idea of vshost characteristics - thanks.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, some additional thoughts regarding Task Manager: - it is not always running; so you cant enumerate its apps when it does not run - when running, another tab may be visible; dont know whether it keeps updating tabs that are not visible... So I strongly suggest you go for the process characteristics... :)

              Luc Pattyn [My Articles] [Forum Guidelines]

              1 Reply Last reply
              0
              • T theFrenchHornet

                As far as I can tell, if the Visual Studio hosting process is enabled, then when Start Debugging is selected, no new process is added. If you look at the Task Manager Processes tab, you see xxx.vshost.exe when the IDE is open and still only see that when the application is being run (debugged). The place where you _can_ tell a difference is the Applications tab of the Task Manager. I know how to get the list of processes that show up in the task manager Processes tab. How do I get the list of applications that show up in the Applications tab? Thanks ...

                M Offline
                M Offline
                Miguel Lopes
                wrote on last edited by
                #7

                string exePath = Application.ExecutablePath; exePath = exePath.ToLower(); if (Application.ExecutablePath.ToLower().IndexOf("devenv.exe") > -1)//design time { } else { }

                1 Reply Last reply
                0
                • T theFrenchHornet

                  As far as I can tell, if the Visual Studio hosting process is enabled, then when Start Debugging is selected, no new process is added. If you look at the Task Manager Processes tab, you see xxx.vshost.exe when the IDE is open and still only see that when the application is being run (debugged). The place where you _can_ tell a difference is the Applications tab of the Task Manager. I know how to get the list of processes that show up in the task manager Processes tab. How do I get the list of applications that show up in the Applications tab? Thanks ...

                  T Offline
                  T Offline
                  theFrenchHornet
                  wrote on last edited by
                  #8

                  Evidently, there is no easy way to access the same information as that in the applications tab of the task manager the way one can easily access the same information as that in the processes tab. Or, if there is, it isn't obvious to any of us. Instead, I used the method below (resulted from suggestion by Luc Pattyn) to determine whether the IDE simply had the application open or was running it. Note - non-relevant portions of code omitted (the ...'s).

                  const string IDE_INDICATOR = ".vshost";
                  Process current = Process.GetCurrentProcess();
                  string IDE_Name;

                  ...

                  if (current.ProcessName.Contains(IDE_INDICATOR))
                  {
                  IDE_Name = current.ProcessName;
                  }
                  else
                  {
                  IDE_Name = current.ProcessName + IDE_INDICATOR;
                  }

                  ... (looping through all processes)

                  if (process.ProcessName == IDE_Name)
                  {
                  IntPtr WindowHandle = process.MainWindowHandle;
                  if (WindowHandle != IntPtr.Zero)
                  {
                  // then application is being run by the IDE
                  }
                  else
                  {
                  // IDE is open with the application loaded, but not currently running it - at least not in debug mode,
                  // and non-debug mode can be detected because it has its own process
                  }
                  }

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, getting the list of items shown by "app" tab in Task Manager is complex; it entails finding the right window (i.e. knowing the names of the windows in its hierarchy), then sending some LVM_... messages to the listview. It must be similar to enumerating the notify icons in the system tray, and the icons on the desktop. Each of these can be found in several CodeProject articles. I dont think reading that list is a very good idea; it is complex and the names you would get are Window titles, which does not necessarily correlate well with the process names... Using TaskInfo I noticed the vshost.exe process has quite different characteristics (CPU time, working set, number of windows, ...) when comparing an idle state with an active debug state. So if what you want to figure out is whether something is being handled by vshost, I suggest you get hold of its PID (using Process class), then do a P/Invoke to either get its main window title, or to enumerate all its windows (zero when not active). :)

                    Luc Pattyn [My Articles] [Forum Guidelines]

                    T Offline
                    T Offline
                    theFrenchHornet
                    wrote on last edited by
                    #9

                    Your idea of getting the main window helped. Thanks.

                    L 1 Reply Last reply
                    0
                    • T theFrenchHornet

                      Your idea of getting the main window helped. Thanks.

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      You're welcome.

                      Luc Pattyn [My Articles] [Forum Guidelines]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups