Windows Service project and how to debug

G

Guest

Hi,

I created a Windows Service project, the installers and the setup project
for the service. Now I have the service installed but once I start it up,
it's taking 100% CPU and not doing anything. I tried attaching the visual
studio debugger to the win service process but it's not stopping at any
breakpoints.

Does anyone have any idea about why it's taking the 100% CPU.
And how can I debug and see what's going on?

Thanks very much in advance!!

Agnes
 
G

Guest

Agnes,

Only you can find out truly what is going on. Here are some suggestions:

First, start your service from within the Debugger and see if you can tell
what is happening.

If that doesn't work. Then start it the way that you just did, then open
Task Manager, go to the Processes page, find your service, right-click on the
service, in the context menu select Set Priority, reduce the priority of the
service, THEN try to attach your debugger.

Remember that the Windows OS uses preemptive multitasking so other
applications (including Task Manager) should eventually get a chance to
execute.

You might have a tight forever loop that may not be setup the way you
expected. Make sure that the installer has set all your initial values (ie.
registry settings, config file values, etc...)

Good luck,

Kim Greenlee
 
A

Alan Pretre

Agnes said:
And how can I debug and see what's going on?

Insert a 30 sec. thread sleep in your main() or OnStart(). That will give
you time to attach the debugger to it, then you can trace it before it
hangs.

-- Alan
 
D

Damien

Agnes said:
Hi,

I created a Windows Service project, the installers and the setup project
for the service. Now I have the service installed but once I start it up,
it's taking 100% CPU and not doing anything. I tried attaching the visual
studio debugger to the win service process but it's not stopping at any
breakpoints.

Does anyone have any idea about why it's taking the 100% CPU.
And how can I debug and see what's going on?

Thanks very much in advance!!

Agnes

Hi Agnes,

Debugging services can be a real pain.

I normally structure my services as three projects:

1) a DLL which exposes a singleton class which has
Start/Stop/Pause/Continue methods
2) a Windows Form application with buttons which hook up to the four
methods
3) a Windows Service which hooks up to the four methods.

So the meat of my service is in the DLL. When I'm debugging, I use the
Windows Form application to run it. When it's released, the service
uses it.

Only problem with this method is that the environment isn't quite the
same for the service, because when it's debugged it's running under my
user account, and it can interact with the desktop, two things unlikely
to be true when it's running normally. This hasn't been a problem for
me.

Damien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top