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. Visual Basic
  4. Debugging A Service???

Debugging A Service???

Scheduled Pinned Locked Moved Visual Basic
visual-studiodebuggingquestion
7 Posts 5 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.
  • G Offline
    G Offline
    GrindAZ
    wrote on last edited by
    #1

    I have created a windows service but how do you run the code in the IDE so you can step through and debug it?

    R A 2 Replies Last reply
    0
    • G GrindAZ

      I have created a windows service but how do you run the code in the IDE so you can step through and debug it?

      R Offline
      R Offline
      Ray Cassick
      wrote on last edited by
      #2

      You have to install it, start it then attach to it in the debugger. This will cause you to miss being able to really debug any code in the starting events.


      Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.


      A 2 Replies Last reply
      0
      • R Ray Cassick

        You have to install it, start it then attach to it in the debugger. This will cause you to miss being able to really debug any code in the starting events.


        Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.


        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        What a pain! Do you know if you can have a System Tray Icon with a menu Associated with your service. I tried setting up a NotifyIcon, it runs through the code to set it up fine but it never appears in the system tray.

        M 1 Reply Last reply
        0
        • A Anonymous

          What a pain! Do you know if you can have a System Tray Icon with a menu Associated with your service. I tried setting up a NotifyIcon, it runs through the code to set it up fine but it never appears in the system tray.

          M Offline
          M Offline
          Mike Mestemaker
          wrote on last edited by
          #4

          One trick I've been using is to put most of the initialization code in a one-shot timer (.AutoReset=False) and set the interval on that timer for something like 30-45 seconds. That gives you the time to connect the debugger to your service before that code starts. Since my service is based around another timer, I just leave my main timer disabled until the initialization timer fires. Put your first breakpoint in the initialization timer and you can then debug that code. Once you are happy with your initialization code, you can speed things up by changing the initialization timer's interval to something much shorter. Don't change the structure for production, just shorten the interval. If you need to re-debug something in the init code, you only have to change your interval again.

          1 Reply Last reply
          0
          • R Ray Cassick

            You have to install it, start it then attach to it in the debugger. This will cause you to miss being able to really debug any code in the starting events.


            Paul Watson wrote: "At the end of the day it is what you produce that counts, not how many doctorates you have on the wall." George Carlin wrote: "Don't sweat the petty things, and don't pet the sweaty things." Jörgen Sigvardsson wrote: If the physicists find a universal theory describing the laws of universe, I'm sure the asshole constant will be an integral part of that theory.


            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Two more questions. 1. How can I make my service handle the Pause and Continue events? I have the code for these events in my service (OnPause and OnContinue) but these selections are not available to me in the Service Manager. Also I wrote a custom app to control services, when I call the pause method against my service I get an exception because the service does not handle these events. (System.InvalidOperationException: Cannot pause Esanti_Core service on computer '.'. ---> System.ComponentModel.Win32Exception: The requested control is not valid for this service) 2. How can I write a service install function from a custom app?

            G 1 Reply Last reply
            0
            • A Anonymous

              Two more questions. 1. How can I make my service handle the Pause and Continue events? I have the code for these events in my service (OnPause and OnContinue) but these selections are not available to me in the Service Manager. Also I wrote a custom app to control services, when I call the pause method against my service I get an exception because the service does not handle these events. (System.InvalidOperationException: Cannot pause Esanti_Core service on computer '.'. ---> System.ComponentModel.Win32Exception: The requested control is not valid for this service) 2. How can I write a service install function from a custom app?

              G Offline
              G Offline
              GrindAZ
              wrote on last edited by
              #6

              Well I found the answer to my first question. You have to set the CanPauseAndContinue property in the InitializeComponet sub. i.e. Me.CanPauseAndContinue = true

              1 Reply Last reply
              0
              • G GrindAZ

                I have created a windows service but how do you run the code in the IDE so you can step through and debug it?

                A Offline
                A Offline
                Anthony_Yio
                wrote on last edited by
                #7

                The easier way of all (in my opinion) is to set up ASSERT and TRACE in your code. Use the Debugview from www.sysinternal.com to trace your code but make sure your service is in debug mode. Or use some debugging tool like softice and etc.

                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