Debugging A Service???
-
I have created a windows service but how do you run the code in the IDE so you can step through and debug it?
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.
-
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.
-
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.
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.
-
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.
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?
-
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?
-
I have created a windows service but how do you run the code in the IDE so you can step through and debug it?
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.