C# Windows Service problem - installer possibly? Some services stop automatically...

K

kevin89065

I have a windows service that I am trying to get working using C# and
WinXP through the .NET framework. I had got the service to run this
morning, however while it was running I realized that I wanted to
change some code and it tried to stop it. It attempted to stop itself
but gave me an error saying that it wasn't able to stop because it had
timed out. Then the service's status in the Computer Management ->
Service and Applications -> Services window was "stopping". It never
changed from this and I restarted my computer and then uninstalled the
service and made my changes to the code, recompiled and reinstalled the
service.

Then from that point on whenever I try to run the service it tells me
that it started and stopped, and some services stop automatically if
there is no work to be done. This is not the case, so there is an error
somewhere else. I have looked in the event viewer and there are no
events that have taken place with this project since it ran the time it
wouldn't allow itself to be stopped(there are no errors in the viewer
from that however), including any event from an MSI installer. This
leads me to believe that possibly something is wrong with that? When I
install the service, it doesn't give me an error and it says that it
installs successfully and it's there in the Services window to give me
the "some services stop automatically" message when I try to start it,
but the installation never gets added to the event log.

Does anyone have any ideas what I can do?
 
K

kevin89065

It turns out the problem was an event log that was full. While
debugging it had entered a loop that it wasn't getting out of and I put
a "Write to event log" action there, and when it finally got through,
it had a ton of events to add to the log, which filled up which
explains why there were no events since the event earlier in the
morning. Once I cleared the event log and took out the statement that
wrote the message in the loop it is fine.
 
B

Brian Gideon

Kevin,

That's a particularly nasty problem with services that write to the
event log. When the log is full there the write will fail and generate
an exception as expected. A lot of people usually put a try-catch
block that will catch all exceptions in a last resort attempt at
keeping the service running. If that exception information is then
written to the event log...Catch-22.

Brian
 
N

Nick

Event logging, while important, isn't often 'critically necessary'...

Wrap your event logging in a try with an empty catch block and allow it to
fail until the cows (or the administrators) come home.


Nick F
 

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